It had all the elements of a classic coup: thousands descending on the capital, clashing with police outside parliament and commandeering state TV to demand the ouster of a civilian leader who had locked horns with the military in a country with a long history of turmoil and dictatorship.

But when the tear gas cleared in Islamabad in August, Pakistan's Prime Minister Nawaz Sharif remained in office with the support of the entire parliament, the troops were still in their barracks, and the protesters had dwindled to a few thousand, their "revolution" confined to a festive, shrinking tent camp.

The uprising led by former cricket star Imran Khan and cleric Tahir-ul-Qadri failed to overthrow Sharif, but it did rattle the conventional view of Pakistan as a tottering state perpetually leaning on an all-powerful army. "Parliament's unanimous support for Nawaz Sharif played a key role in saving democracy in Pakistan," political analyst Mahdi Hasan said.

Khan and Qadri had accused Sharif of massive fraud in the 2013 election that brought him to office in Pakistan's first-ever democratic transfer of power. International monitors reported irregularities in the vote, but have not questioned the outcome.

Beyond the voting allegations, Khan and Sharif are longtime political opponents, while Qadri holds Sharif personally responsible for the deaths of 14 of his supporters in clashes with police in Lahore in June.

At the peak of the protests in August some 70,000 people thronged the heart of the capital. On Aug. 30 the demonstrators burst through security barricades and clashed with police outside parliament. The police fired tear gas and rubber bullets. Three people were killed in the melee and another 500 — including police — were wounded.

The military, which had troops deployed to back the police, might have chosen that moment to side with the protesters and push for Sharif's ouster. The army overthrew Sharif in 1999, ending his previous stint as prime minister. More recently the army had clashed with him over his decision to bring a treason case against Pervez Musharraf, the general who had ousted him, and his support for a private TV channel that accused the country's spy chief of trying to kill its top anchor.

But instead of sweeping Sharif from power, Pakistan's powerful army chief Gen. Raheel Sharif met with the protest leaders to try to convince them to resolve the impasse.

Critics of the protesters say the military should have intervened to disperse them. Defense analyst Talat Masood said the army's "reluctance to forcefully resolve the crisis encouraged the demonstrators."

The army says it deployed troops to protect government buildings but that it was up to the 30,000 police and paramilitary groups — who take orders from government — to handle crowd control.

In the end, most of the protesters left on their own. Qadri officially ended his sit-in in Islamabad this week. Khan's supporters remain, but it's unclear whether the crowds of mainly college students that swell in the evenings are drawn there for political reasons or to hang out and hear popular singers who regularly perform at the rallies.

Sharif's government has said it is ready to let Khan use an open-air theater to "entertain their supporters."

Most of Khan's supporters in parliament, where his Tehreek-e-Insaf party had been the third largest bloc, have resigned from the assembly. And Javed Hashmi, who was president of Khan's party, broke with him over the decision to march on the prime minister's house on Aug. 30. Like other critics, he raised the specter of military involvement in the protests, alleging Khan had endangered democracy. Both Khan and Qadri have denied conspiring with the military.

The protests have not been a complete failure. In August Sharif announced the formation of a judicial commission to probe the vote rigging allegations. Khan and Qadri have rejected the commission, but Ishaq Dar, the chief government negotiator in talks with the protesters, says Sharif will step down if the commission finds that the election was fraudulent.

"We will have no moral authority to remain in power if the commission finds us guilty of rigging the elections," Dar said.