Nawaz Sharif has been endorsed as Pakistan's new prime minister, beginning an unprecedented third term with the country facing a daunting array of problems.