In such a system, even steps like Mr. Sharif’s removal, which nominally reinforce accountability and the rule of law, can deepen decidedly undemocratic norms.

Though justice prevailed, so did perceptions that it is applied selectively. Though corruption was punished, so was, in the eyes of many of Mr. Sharif’s supporters, defiance of the military.

The country has shown it can lawfully remove a prime minister, but it has also shown that voters, who have been allowed to decide only one peaceful transfer of power, still have their leaders selected for them. They are spectators foremost, and participants only occasionally, in their country’s democracy.

Accountability as a tool

Many Pakistanis quickly noticed something that suggested Mr. Sharif’s removal might perpetuate, rather than end, the undemocratic norms that have plagued Pakistan for decades.

The Supreme Court has pursued Mr. Sharif but sidestepped many of the other politicians and officials implicated in the Panama Papers leak that set off the investigation, leading to accusations that it was pursuing selective justice.

“Moral of the story: when with the establishment, you will not be touched,” Asma Jahangir, a prominent human rights lawyer, wrote on Twitter, adding, “but if you disagree your grand mom will also be investigated.”

This common perception — that politicians serve their own interests and that accountability is deployed according to the whims of the elite — matters. Those expectations help entrench such behavior as a norm, making it more likely to recur.

This problem extends beyond Mr. Sharif. Tax evasion rates in Pakistan are notoriously high, particularly among the wealthy. Transparency International, a corruption watchdog, ranked the country 113 out of 176 countries in its corruption perceptions index.

Though laws against corruption are strongly written, they are underenforced. And weak elected institutions are easily corrupted. Together, that means that nearly any leader is vulnerable to prosecution and removal if other institutions choose to single him or her out.

But each time they do so, they reinforce the belief impression that true power lies with the so-called hidden hands, powerful military and other elites who manipulate the system according to their own wishes, not with voters.

The decision in Mr. Sharif’s case, which took a very broad view of the constitutional clauses requiring politicians to be “honest and reliable,” risks exacerbating perceptions that justice is often a means to a political end.

“The clause under which he was removed essentially means all of Pakistan is ineligible,” said Adil Najam, the dean of Boston University’s School of Global Studies and an expert on Pakistan’s politics.

Accountability, in such a system, can also be a tool for targeting rivals. This weakens the expectation of punishment, which is supposed to deter future corruption, as well as the ability of healthy institutions to self-regulate.

Disrupting democracy

Mr. Sharif’s removal, even if it does discourage corruption, repeats a pattern that has recurred throughout Pakistan’s history and has been at the core of many of its worst problems. Unelected power centers, not voters, decide who rules.

Only one prime minister has left office in a democratic transition, in 2013. The rest have been removed by “judges, generals, bureaucrats or assassins,” Husain Haqqani, the former Pakistani ambassador to Washington, wrote on Twitter, calling it Pakistan’s “70-year tradition.”

If Mr. Sharif had finished his term and faced elections again, that would have been a second peaceful transition, a milestone many political scientists see as a vital step in consolidating democracy.

“You want elected officials to be judged by the population on the basis of their record,” said Paul Staniland, a University of Chicago political scientist who studies Pakistan.

Ideally, Mr. Staniland said, successive elections would establish voters, not unelected bodies, as the final arbiters. Beyond being the point of democracy, this makes leaders accountable to the interests of their nation as a whole, rather than those of a few powerful elites.

Democracy fully takes root only when all aspects of the political system assume that final authority rests with voters and elections. For Pakistan, after so many coups and assassinations, persuading everyone of this would take time.

“These interventions disrupt that,” Mr. Staniland said, by sending the message that elites can continue assuming that they, not voters, still decide who rules.

Cycles of instability

Those interventions are possible because of an imbalance in the strength of Pakistan’s institutions. The military and courts are powerful and highly trusted by the public. By contrast, elected institutions, especially political parties, are weak.

The result is that instead of one institution checking another in ways that strengthen the democratic system, those institutions undermine one another’s already scant legitimacy, leaving the stronger unelected bodies to intervene again and again.

Individual checks like the removal of Mr. Sharif, however justified, chip away further at the legitimacy of those institutions. They remain just relevant enough to jostle for power, ensuring more such cycles, but too weak to actually clean out the system — a recipe for instability.

With each such case, those institutions are also on trial. In a healthier democracy, finding a politician guilty proves the system works. In Pakistan, where elected institutions are often assumed to be corrupt, it can mean, in the eyes of voters, indicting the system as just as guilty.

Imran Khan, an opposition leader, has pursued Mr. Sharif’s ouster for years, filing court petitions and leading public protests to press watchdog groups and now the Supreme Court.

The military also opposed Mr. Sharif, in part because he sought reconciliation with India, Pakistan’s rival. That does not mean the military played any role in Mr. Sharif’s ouster. But it fed into perceptions that he was outside the good graces of Pakistan’s power brokers, leaving him vulnerable.

“I could tell myself a happy story in which this marks the judiciary asserting the rule of law and getting everything on the right course,” Mr. Staniland said. “But I think that’s pretty unlikely.”

A more plausible reading, he added, is that “justice is applied inconsistently and will be used to target parties and institutions that will then be unable to recover.”

This has led to a norm, Mr. Najam said, of parties seeking to defeat one another not in elections but by creating the conditions for a military or judicial coup against them.

Without a break from Pakistan’s regular cycles of collapse, political institutions cannot grow stronger, and so cannot provide the real accountability and democracy that voters demand.

“Pakistan has always been in this place,” Mr. Najam said. “Every democratic government in Pakistan that has fallen, and all of them has fallen, has fallen on the sword of supposed accountability.”