The framers of the U.S. Constitution feared that democracy could devolve into rule of the mob. Events in Egypt are a reminder of why that concern was justified. Essentially the same prodemocracy activists who enabled Hosni Mubarak to be removed from power in February 2011 have now done the same to his democratically elected successor, Mohammed Morsi. In both cases it was the protesters who made the government vulnerable. And in both cases it was the army that delivered the coup de grace in the form of a coup d'etat.

Even acknowledging that Morsi and his Muslim Brotherhood-backed party did a poor job in their year in power, failing to win over opponents or broaden their base of support, the latest coup is a tragic setback for democracy, constitutionalism and the rule of law.

The first protests of the Arab Spring were calls to replace a dictator who had no democratic right to govern. The protests were inspiring not just because they said "enough" to a bad system, but also because the protesters aspired to replace that bad system with democracy. Many of the original protesters wanted a secular government. But by calling for free elections, they opened themselves to the possibility that the majority of Egyptians wouldn't agree. That is democracy: The majority gets to choose the government it wishes, subject to the guarantee of minority rights.

When the Islamists were elected by clear majorities in legislative and presidential elections, the secularists didn't much like it — but at first they accepted the results as legitimate. The constitutional drafting process that followed was truncated and in many ways inadequate, but the constitution that emerged was approved by the public in yet a third demonstration that a majority (if not a large one) accepted the government as democratically legitimate. And indeed, the flaws in the constitutional process were caused in no small part by Morsi's justified fear that the constitutional court would trigger a military coup by declaring the assembly unlawful.

Over time, however, Egyptians who never liked Morsi became impatient. In an astonishing show of bravado, they announced, with plenty of warning, that they were going to begin huge protests on June 30 — essentially advertising their plans to shut down the country and asking the army to intervene.

You might think that replacing an unpopular, Islamist leader is a victory for democracy. It isn't. In a functioning democracy, there is an orderly constitutional process for protesting and removing a leader. When someone is elected for a term of years, he should serve them out unless he resigns or is impeached. The popularity ratings of U.S. presidents regularly sink below 50 percent — George W. Bush's fell into the 20s — but that doesn't mean they should be removed from office. The president needs a majority only when elected, not at every subsequent moment. This applies to a president who is doing a bad job and even to a president who is violating the Constitution. (Who then, by the way, should be removed by a constitutional process if at all possible.)

What distinguishes constitutional democracy from mob rule is that orderly processes are followed. And what distinguishes it from autocracy is that the military doesn't get to choose who rules. The Egyptian people as a whole are not getting rid of Morsi. The army is, with cover provided by the protesters who lost at the ballot box.

What will happen next is sadly easy to foresee. A caretaker government will continue to have the strings pulled by the military. Don't expect elections soon, because it's entirely possible that the Islamists would win. If there are elections, don't be surprised if the Islamists are banned from running. Like Iran, Egypt will be an autocracy with elections.

Should we expect the Brotherhood to fight back and ignite a civil war? Probably not. The group has a long history of avoiding violent clashes with the military; it prefers to bide its time and build public support. Still, it's a sign of Egypt's newfound volatility that the possibility lands within the realm of reality.

Today, the loser is not just democracy in Egypt but democracy itself. Other nations that choose to rise up against illegitimate leaders may want to forgo elections altogether, opting for the guardianship of an army or revolutionary vanguard. Or they may embrace the Chinese model, finding its calm, order and authoritarianism more appealing than the wild ride of democratic elections.

America's choice of democracy was considered unwise by many in its time. Only our Constitution, with its checks on the mob, consolidated democracy and allowed it to become popular worldwide. Today the antidemocrats, past and present, are doubtless feeling self-satisfied with their newly won appeal. Let's hope the glory is fleeting.

Noah Feldman is a law professor at Harvard University. He wrote this article for Bloomberg News.