Pakistani Prime Minister Nawaz Sharif addresses the 68th United Nations General Assembly at U.N. headquarters in New York in September. (Reuters)

The last time Nawaz Sharif traveled to Washington as Pakistan’s prime minister, in 1999, he was just months away from being overthrown in a coup that left him in exile and his country under military rule for more than a decade.

On Sunday, Prime Minister Sharif returns here for an official visit in a far more secure position. He was elected in May in Pakistan’s first-ever transfer of power from one civilian government to another, his party holds a firm parliamentary majority, and the military has at least nominally moved away from politics.

The agenda for Sharif’s talks with President Obama, Cabinet officials and lawmakers is fraught with touchy subjects, such as the administration’s ongoing, if diminished, drone strikes against suspected terrorists harbored in Pakistani territory, congressional reluctance to continue large aid programs and Pakistan’s growing nuclear weapons arsenal.

But neither country wants to return to the roller-coaster relations that touched bottom in 2011, when a U.S. raid in Pakistan killed Osama bin Laden and a NATO airstrike killed 24 Pakistani soldiers near the country’s border with Afghanistan.

“There were hiccups in 2011 and 2012, but we truly believe things are getting better,” said Sartaj Aziz, Sharif’s foreign affairs adviser.

A senior State Department official echoed those sentiments. “For a variety of reasons, there’s a bit more optimism and hope in the relationship, I think, on both sides than there has been for a while,” said the official, who, like several others interviewed, was not authorized to discuss the subject on the record.

To reflect and encourage the improvement in relations, the Obama administration has moved to speed the release of more than $1 billion in previously approved military and economic assistance — as well as promised compensation to the Pakistani military for counterterrorism expenses — that has been doled out sparingly in recent years.

The optimism comes despite Sharif’s aggressive stance toward the continued drone strikes, which analysts in both countries said he has little choice but to condemn because the attacks are deeply unpopular in Pakistan.

Two weeks after he took office, Sharif lodged a formal complaint with the U.S. Embassy after a drone strike killed seven militants in North Waziristan in the country’s restive tribal region. He also spoke out against the strikes — which have totaled about 20 this year — in his speech to the U.N. General Assembly last month.

The Obama administration has its complaints, including what officials think is ongoing support for Afghan militant groups in the tribal areas by the Pakistani military’s Inter-Services Intelligence agency. The ISI is thought to turn a blind eye to movement across the Afghan border by members of the Haqqani network, who, among other things, are held responsible for last month’s attack on the U.S. Consulate in Herat, Afghanistan. The intelligence agency is also suspected of facilitating travel documents for Haqqani figures to visit funders in Persian Gulf states.

Yet U.S. officials say Sharif has sent numerous signals that he is ready to reduce tensions. In late June, they credited his government with helping nudge the Afghan Taliban to Qatar for what was ultimately an unsuccessful attempt to jump-start peace talks between the insurgent group and Afghan President Hamid Karzai’s government.

And in August, analysts said they were surprised at Sharif’s relatively muted response to a Washington Post story that outlined U.S. intelligence agencies’ deep mistrust of Pakistan and their doubts about its stability.

Both countries are concerned about Afghanistan, although for different reasons. U.S. officials are working to avoid a resurgence of the Taliban, while Pakistan has far more parochial worries about whether postwar Afghanistan
will be stable and well-financed enough to prosper.

According to various estimates, 1.5 million to 3 million Afghan refugees from various upheavals live in Pakistan. Already struggling with billions of dollars in debt and a stagnant economy, Pakistan is ill-equipped to handle a new refu­gee crisis.

What Pakistan wants in Afghanistan “kind of depends on who you talk to,” the State Department official said. The “ideal situation,” from Pakistan’s perspective, is that reconciliation talks between the Afghan government and the Taliban succeed and that “the Taliban lay down their arms and go back into Afghanistan to become significant political players and the dominant faction in the south and east of the country. . . . They’d like us to facilitate that.”

Pakistan sees the Taliban as a buffer against Afghanistan moving too close to India, Pakistan’s historical enemy.

If security tops the Obama administration’s agenda, Pakistan’s economy tops Sharif’s, the U.S. official said. “That’s what he got elected for, and that’s what he campaigned on. But he recognizes — and that recognition is reinforced by what he’s heard from others, China for instance — that Pakistan isn’t going to get international investment, not just from the West but from anywhere, unless they get a handle on their security situation.”

The administration has continued to push Pakistan toward taking military action against the Haqqani network and other Afghan Taliban groups. But Sharif has been steadfast in saying he is more interested in trying to arrange peace talks with the Pakistani Taliban, a separate but related group whose objective is to replace Pakistan’s democratic government.

U.S. officials say that they don’t think Sharif seriously believes such a negotiated peace is possible but that he feels he must make an effort to garner political support for pushing the military to launch offensive operations against the Pakistani group.

In the meantime, the lack of action against both Afghan and Pakistani militant groups remains an irritant to Washington.

“Mr. Sharif appears to be dithering on this issue, and the dialogue that was supposed to start has not gone anywhere,” said Zahid Hussain, a security analyst in Islamabad. “I think that will be a concern for the United States.”

For many in Pakistan, progress would be a U.S. attitude that does not see every aspect of the relationship through the prism of Afghanistan or al-Qaeda.

“When U.S. diplomats come here, it seems like they are prepped for a different country,” said Sherry Rehman, Pakistan’s ambassador to Washington from November 2011 until May. “We have to train the Kabul out of them.”

Craig reported from Islamabad.