Now that Mr. Sharif is poised to return as prime minister of Pakistan for the third time in 20 years, the success of his relationship with the generals will revolve around two related questions: Has he changed? And have they? Many analysts believe he has new tools at his disposal, and in recent days he has played down the prospect of conflict with the army. Much of the hopeful talk surrounding his landslide victory on Saturday is focused on how Mr. Sharif seems different — more mellow, less authoritarian — than during his two previous stints as prime minister in the 1990s. And he returns to power with a mandate from Pakistani voters who have apparently given his party a near outright majority in Parliament. When the military deposed him in 1999, he had earned the displeasure of its leadership for his outreach to India — which this week he promised to renew — as well as his clumsy attempt to fire the army chief, Gen. Pervez Musharraf. Since then, the military has faced several humiliations, including the American commando raid that killed Osama bin Laden in 2011, that have hurt its public image. And under Gen. Ashfaq Parvez Kayani, the army has shown little public appetite for openly meddling in politics, much less mounting another coup. Against that backdrop, the success — and perhaps length — of Mr. Sharif’s tenure will be determined by how he negotiates the relationship with Pakistan’s unelected power players. They include the United States, an ally with whom he has a long and sometimes unhappy history and that has worried about his vigor in fighting Islamist militants. There is a newly crusading judiciary to gauge. And above all loom the generals, and his tense history with them. His career was midwifed in the mid-1980s by Gen. Mohammad Zia ul-Haq, the military dictator, then cut short by the 1999 coup that brought General Musharraf to power. Mr. Sharif spent years in exile in Saudi Arabia. Bitterness from that painful episode was widely believed to have colored Mr. Sharif’s attitude to the army after he returned to Pakistan in 2007. For a time, he regularly hurled rhetorical broadsides at the military that made even members of his own party, who are pro-military by inclination, uncomfortable. In recent months, Mr. Sharif has adopted a more conciliatory tone. On Monday, he glossed over any differences, telling reporters that his problem had been with General Musharraf’s coup, not with the military as a whole. “I think the rest of the army resented Mr. Musharraf’s decision,” he said. “So I don’t hold the rest of the army responsible for that.” Still, there are hints that Mr. Sharif will insist on asserting his authority in ways that could put the generals on edge. In interviews with the Indian news media in recent days, Mr. Sharif stressed his desire to normalize relations with New Delhi — a subject that the army, which has fought three major wars with India — views as its central concern. “Those statements might seem normal to outsiders,” said Cyril Almeida of Dawn, a leading English-language newspaper in Pakistan. “But inside the army it could set alarm bells ringing.” On a different front, the country’s newly assertive Supreme Court also presents Mr. Sharif with a challenge, and perhaps some opportunity. The previous government found itself embroiled in legal battles with the buccaneering chief justice, Iftikhar Muhammad Chaudhry, who conducted his longstanding rivalry with President Asif Ali Zardari and his Pakistan Peoples Party through a series of high-profile court cases. At the same time, judges have been relatively lenient with Mr. Sharif. Cases related to bank loans that his family defaulted on in the 1990s, and payments that Mr. Sharif received from military intelligence about the same time, all received relatively light treatment. “The Supreme Court only had one eye, and it was trained on the Peoples Party,” said Ayaz Amir, a former lawmaker from Mr. Sharif’s party. But now that he is in power, Mr. Sharif’s cozy relationship with the courts could come under strain. Under Justice Chaudhry, the courts have amassed new powers, hauling senior government officials before judges to account for their failings on matters ranging from blatant corruption to the weaknesses of the traffic system. Analysts say Mr. Sharif, who also has a stubborn streak, could find himself drawn into a clash with Justice Chaudhry. “Sharif might look at this court and find it a bit too activist for his liking, with its tendency to push government up against the wall,” said Mr. Almeida, the journalist. “I don’t think he would look on it very benignly.” Still, the potential for conflict may be limited: Justice Chaudhry is set to retire in December, which leaves relatively little time for a battle between the courts and Mr. Sharif.