When protesters converged on the Pakistani capital of Islamabad to demand the resignation of Prime Minister Nawaz Sharif, many were quick to see the hand of the military pulling the strings behind the scenes. Sharif, who became prime minister in 2013 after Pakistan’s first full transition of power from one democratically elected government to another, irked the army during his first year in office. He put former military ruler Pervez Musharraf — who overthrew Sharif in a 1999 coup — on trial for treason. He tried to carve out an independent foreign policy — the traditional preserve of the army — including promising better relations with India. The protests, led by cricketer-turned-politician Imran Khan and cult religious leader Muhammad Tahir-ul-Qadri looked like a means of putting Sharif in his place.

Then, with Sharif refusing to resign and the protesters turning increasingly violent over the weekend, the showdown appeared to be following a familiar course. If Pakistan became ungovernable, the Pakistan army would be “forced” to intervene and take over to restore order. It had happened before. In 1977, General Zia-ul-Haq seized power ostensibly to end a political crisis. Throughout the 1990s, elected governments were repeatedly changed as political parties moved through a revolving door pushed by squabbling politicians and spun from on high by the army and its Inter-Services Intelligence (ISI) agency.

This time around, however, events are not following the script. In what could become a watershed for Pakistan’s fragile democracy, civilian politicians are fighting back. Political parties, with the exception of Khan’s Tehrik-e-Insaf (PTI), rallied behind the government. PTI’s own president, Javed Hashmi, broke with his leader to accuse him of acting on the behest of the army in the hope of forcing fresh elections. A statement released by the army — which appeared to draw equivalence between the mob besieging Islamabad and the elected government — was quickly called out by the English-language media. The army statement advised the government against the use of force and said that if the situation were not resolved quickly, it would play its part “in ensuring security of the state” — an apparent warning that it could take over. In response, a remarkably forthright editorial in Dawn pointed out that “it is the government that is supposed to give orders to the army, not the other way around.” The Nation also declared the army to be out of line and pointed out that the military would not hesitate to use force if violent protesters besieged its own headquarters. On Tuesday, the government called a joint session of both houses of parliament to reaffirm support for democracy.

So what happened to the script? Has Pakistan’s democracy matured to the point where civilian governments can no longer be so easily dismissed? The answer may not be entirely clear for a few days or weeks yet, and will depend on Sharif’s own ability to show flexibility in accommodating opponents inside and outside of parliament.

Or did this coup, by other means, stumble not just because of the resistance of the democrats, but also because the military itself was hesitant about delivering the fatal blow? Are some parts of the security establishment eagerly cheering on Khan and Qadri while others ready themselves to settle for a weakened prime minister still in place? After all, retaining the trappings of democracy would avoid the international disapproval and U.S. sanctions that might follow an outright coup. (Officially, the army denied backing the protesters in a statement that insisted it was an apolitical institution.)

Pakistan’s security establishment — a term that covers everyone from army chief General Raheel Sharif, to his fellow Corps commanders, to the ISI, to retired officers who may or may not be acting under official orders — is notoriously opaque. All that can be said, then, is that Khan has been useful to the security establishment in the past, but either has a tendency to go his own way, or draws his support from particularly hard-line elements.

A few years ago, for example, Khan became one of the most vocal campaigners against drone strikes in Pakistan’s Federally Administered Tribal Areas (FATA) and against the U.S.-led campaign in neighboring Afghanistan. His campaigns were particularly useful to an army that liked to tell the United States that domestic opinion — albeit domestic opinion it had helped manufacture — prevented it from doing more against Islamist militants. Yet more recently, his insistence on holding peace talks with the Pakistani Taliban annoyed some in the army who believed they should be fought more aggressively. Khan’s commitment to defending the people of FATA was conveniently forgotten as soon as the Pakistan army launched its own military operation this year in North Waziristan, which produced one million internal refugees.

In the run-up to the elections, Pakistani media suggested that Khan was a particular favourite of Lt. Gen. Shuja Pasha, then head of the ISI. The former cricketer, not well known for his critical thinking, happily espoused the army narrative that all of Pakistan’s problems could be blamed on its corrupt politicians, while disregarding the military’s own powerful role in setting policy. Yet moving Khan from a single issue player as an anti-drones campaigner to the national political stage proved extremely hard even for a powerful intelligence establishment with many friends in the media. Khan picked up genuine support from those tired of existing political parties, particularly from a younger, urban generation. His unseen friends in the security establishment made sure he was given ample coverage in the Pakistani media, while the international media duly promoted a man with a glamorous international playboy past and pukka English.

But he could not win. Rightly or wrongly, Pakistan has a U.K.-style, first-past-the-post system in which the mastery of constituency politics matters more than overall voting percentage. Sharif’s Pakistan Muslim League-Nawaz (PML-N) has taken years to build and foster its constituency. In the 2013 elections, it came out nearly 100 seats ahead with an absolute majority in parliament. During this year’s protests, Khan tried to accuse Sharif of having won only through massive rigging. In reality, he was so far ahead that even if PML-N victories had been overturned in some constituencies, Sharif would still have won — a view borne out by subsequent opinion polls giving him a strong showing, particularly in the heartland Punjab province.

Khan’s failure to bring out enough supporters in the elections was repeated in this year’s protests. Even after he joined forces with Qadri in the hope of bringing out the masses in a “revolution” against the elected government, neither man could muster the numbers they needed. In a country with a population of more than 180 million, the number of protesters laying siege to Islamabad rarely went past a few thousand. Neither Khan nor Qadri could ever really have hoped to be taken seriously as leaders of a true revolutionary movement on behalf of ordinary people without challenging the role of the military establishment, which consumes more than a quarter of the annual budget.

Yet despite his lack of numbers, Khan continued to insist on the resignation of the prime minister rather than trying to extract concessions and withdraw to fight another day. Perhaps he was given a false idea from some within the security establishment that the army would move in his favor, force Sharif to resign, and call fresh elections that he expected PTI to win. Certainly, his former political ally, Javed Hashmi, gave that impression when he told the Pakistani media that Khan himself cited army support and promised elections in September. Or perhaps his failure to rally enough discontent gave the army cold feet.

Either way, barring any new surprises, the coup by other means appears to have run its course. It was a tawdry affair. An elected government and prime minister were chastened by a mob — a mob, moreover, that was very possibly encouraged by the military. The concessions Sharif made to the army in the course of the showdown will become clearer in the coming weeks, particularly if Musharraf is allowed to leave the country. Khan’s intransigence and willingness to put his personal ambition above support for democracy badly tarnished his reputation. The army came away looking less than sure-footed and perhaps fragmented. Yet remarkably, the fragile democratic transition survived. It is now up to Sharif — who has a reputation for autocracy and a tendency to rely on family members — to make the parliamentary system work and ensure his government is properly accountable to the electorate by delivering good governance.

Myra MacDonald is a former Reuters journalist who has worked in Europe, the Middle East and South Asia. She was Chief Correspondent in France and Bureau Chief in India. After publishing Heights of Madness, a book on the Siachen war between India and Pakistan, she has focused in recent years on writing about Pakistan.

Photo credit: Mustafa Mohsin