Clip_11 (2)The news from Pakistan is often terrible. There was violence leading up to the parliamentary election. At least Pakistan did manage to have an election in which about 60 percent of voters participated and has achieved a peaceful transition of power in a country where coups have predominated. The election was a welcome repudiation of militants who are trying to overthrow the state.

Pakistanis deserve credit for their courage, and the military for allowing the election to go ahead and deploying 73,000 troops to keep order. And while serious charges of vote-rigging must be investigated, it appears that most Pakistanis are willing to accept that former PM Nawaz Sharif and his party will dominate the next Parliament.

Sharif, who lives in his palatial home outside Lahore, replete with stuffed lions and gilded furniture, faces staggering challenges.

With the economy in a death spiral, he wisely made his finance minister his first appointment, selecting Ishaq Dar. Mr. Dar held that job twice in the 1990s. Mr. Sharif is a fiscal conservative who favors free-market economics. His tasks are to reduce a bloated public sector, end energy shortages and persuade Pakistanis to pay taxes, without which the government cannot hope to stabilize the economy.

Making peace and fostering trade with India would advance that goal.

A major obstacle to effective civilian rule in Pakistan and peace with India, has been the military. Sharif returned from exile in 2007 to build a new political movement. The Army has since withdrawn from an overt political role, yet it remains a potent force.

Repairing badly damaged relations with the United States will be another major test.

Sharif has major differences with the American government, including his tendency to coddle terrorist groups and his opposition to drone strikes, but he has worked with the United States in the past and should try again.

Ultimately, the success of democracies and the politicians they produce depend on good governance. It is up to Sharif to prove that strong civilian leadership can turn things around in Pakistan.

The last time that Nawaz Sharif had close dealings with the Pakistani Army, soldiers handcuffed him and imprisoned him in an ancient fort overlooking the Indus River, physically dragging him from office in a coup.

The success of his relationship with the generals will revolve around two related questions: Has he changed? And have they?

He has new tools at his disposal. Much of the hopeful talk surrounding his landslide victory is focused on how Mr. Sharif seems different — more mellow, less authoritarian — than during his two previous stints as PM 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.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. 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 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. Now he glosses 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.

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, who conducted his longstanding rivalry with President Zardari and his PPP 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.

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. 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 Sharif.

On the campaign trail, Mr. Sharif played to populist sentiment by condemning drone strikes in the tribal belt and suggesting, in vague terms, that he would seek to avoid bowing to American dictates. But the perilous state of Pakistan’s economy means that he may require American support for a bailout by the IMF — one that economists believe will be necessary in the coming months.

Behind the scenes, American diplomats are likely to pressure him for stronger action against militants.

Sharif was measured in the campaign in his criticism of the Taliban, which notably did not attack his party’s election events as they did those of more secular parties. Indeed, the perception that Mr. Sharif had an ambiguous view, at best, toward militants was a constant source of tension with American officials during his first stints in office.

Sharif may now come under pressure — from the army as well as the United States — to clamp down on militant havens in his home province of Punjab, parts of which have become hotbeds of sectarian violence led by Sunni extremist groups.

But in foreign policy, Mr. Sharif has another source of support: his close relationship with Saudi Arabia, where he whiled away his exile. King Abdullah helped broker Mr. Sharif’s return to Pakistan in 2007, and Sharif maintains close ties with Riyadh. That relationship, although discreet, could provide an alternative source of economic aid, as well as a powerful ally.

His old nemesis, General Musharraf, is under house arrest at his villa outside Islamabad over several judicial prosecutions. The Supreme Court has decreed that Mr. Sharif’s administration will have to decide whether the former army ruler should face treason charges, which carry a possible death penalty.

A steel baron by background, and conservative by inclination, Mr. Sharif has long had a reputation as a man who does not forgive or forget. The Musharraf case presents him with an obvious opportunity for revenge. But even critics say he has softened over the years, and is more likely to take a lenient approach in the interest of avoiding an unnecessary confrontation with the army.

He’s a more mature person now, less impulsive than before. It would be foolish to start settling scores. The Musharraf case will be a major test of that.