Supporters of Pakistani opposition politician Imran Khan take part in a rally in Islamabad, Pakistan, in April. Just recently enjoying unusual stability, Pakistan is once again teetering on a political crisis. (Faisal Mahmood/Reuters)

Pakistanis appear to be deciding that, yet again, there is only so much good news they can handle.

Over the past two years, Pakistan has appeared to be rebounding from a miserable decade.

Major terrorist attacks continue to decline, building off the nine-year low recorded in 2015. The economy has settled, and a plan by China to invest billions to upgrade Pakistani shipping routes remains on track. And some previous hardships of everyday life here, such as hours-long power blackouts, are easing — at least for now — in major cities.

But Pakistan now finds itself on the brink of another self­inflicted crisis as Prime Minister Nawaz Sharif struggles to fend off calls for his resignation while the country’s relationships with the United States and neighboring Afghanistan deteriorate.

“Pakistan has lost its moment,” said Zahid Khan, a leader of the country’s moderate Awami National Party. “And the reason is that the political parties are immature and they lack a vision.”

The roots of the latest tension can be traced to the country’s vicious and vindictive political system, the military’s unwillingness to sever its ties to the Taliban insurgency in Afghanistan and diffused leadership that can pit a prime minister against his army.

Two years ago, Sharif reportedly had to cede a chunk of his power to the military in exchange for not toppling him during disruptive street protests.

Sharif rebounded from that humiliation, winning over Pakistanis with new public works projects and economy-building foreign investment.

Now, the organizer of those protests — former cricket star Imran Khan — is back at Sharif’s doorstep over allegations that his family stashed some of its vast wealth in overseas bank accounts.

The military, at the same time, is under growing stress over doubts about whether it can be trusted to help end the war in Afghanistan.

“A few months back, things were seemingly moving in the right direction,” said Hassan Askari Rizvi, a political analyst in Lahore, “but it’s back to an incoherent situation.”

The dramatic and sudden turnaround in the political and diplomatic mood has bolstered the view of some analysts that the country is simply allergic to stability.

In 2014, Pakistan’s military finally got tough and launched an operation to drive Islamist militant groups from the country’s northwestern tribal belt.

Around the same time, army chief Raheel Sharif appeared to be invested in trying to work with the United States and China to broker a peace agreement between Afghanistan’s government and Taliban leaders who have historically found refuge in Pakistan.

But peace talks have failed to materialize, and both Afghan President Ashraf Ghani and the U.S.-led coalition in Afghanistan are losing patience. A particular frustration is that Pakistan has not done more to disrupt the Haqqani network, a Taliban offshoot.

In response, after returning from a trip to Afghanistan, Senate Foreign Relations Committee Chairman Bob Corker (R-Tenn.) led a bipartisan effort to block U.S. subsidies for a $699 million deal to sell Pakistan eight F-16 fighter jets.

The House Armed Services Committee has also approved language to block $450 million in military aid unless the Pentagon certifies that Pakistan is working with Afghanistan to “block the movement of militants including the Haqqani Network.”

Dan Feldman, the former State Department special envoy to Afghanistan and Pakistan, said he worries that the congressional actions will be viewed as “punitive.” The United States still generally considers both Sharifs to be allies, he noted.

“Certainly, there may be very legitimate and compelling reasons to be frustrated with the Pakistanis, but I would say the path forward is not to isolate them,” Feldman said.

Still, he noted, “Pakistan has a long history of missing opportunities.”

Indeed, dating at least to the 1970s, there have been numerous periods when Pakistan appeared ready to evolve into a more stable democracy, only to slide into the next crisis.

The concern now is that Pakistan is once again teetering.

Three years after Pakistan completed its first transfer of power from one democratically elected government to another, Sharif is struggling to withstand the backlash from allegations that two of his children hold offshore accounts.

When the allegations first surfaced in the Panama Papers last month, few Pakistanis seemed surprised that a wealthy politician — who had already been forced to flee the country once when he was ousted in a 1999 coup during a previous term as prime minister — may have ties through his family to offshore bank accounts or have failed to pay taxes.

But Khan, founder of the Movement for Justice party, seized on the news to further his arguments that Sharif is corrupt and his political party, the Pakistan Muslim League-N, won its majority in Parliament through fraud.

In a rowdy appearance before Parliament on Monday night, Sharif defended his family’s wealth and said that all offshore assets were purchased with money acquired in business deals overseas.

“My hands are clean,” Sharif said, adding, “today’s Pakistan is more stable and more bright” than it was when he took office.

But Pakistan’s powerful military is not rushing to back him, and some analysts suspect that it may be even quietly supporting efforts to oust him.

Two weeks after the Sharif family’s offshore accounts were disclosed, the army chief fired six senior officers for alleged corruption. Raheel Sharif has also vowed to wipe out “the menace of corruption” in Pakistan.

“This was seen as a warning, and I see big problems for Nawaz right now,” said Zahid Hussain, an Islamabad-based security analyst.

Marvin G. Weinbaum, a Pakistan expert at the Washington-based Middle East Institute, said the military may be using the Panama Papers revelations to scare the prime minister into ceding more power.

“The question is how badly do they want [Sharif] damaged,” Weinbaum said, “and what do they ultimately want?”

Shaiq Hussain in Islamabad contributed to this report.