With Egypt soon to head into the final round of its first presidential elections, deposed dictator Hosni Mubarak looks to be on his last legs. Though a court recently sentenced him to life in prison, Mubarak looks not to have much life left in him, and is reportedly slipping in and out of consciousness. His sentence is largely irrelevant to Egypt’s political future, but it reflects growing discontent inside the country.

To many Egyptians’ dismay, the prosecution never explicitly charged Mubarak for the deaths of over 800 civilians during the revolution. As a result, the court’s ruling is the worst of all possible worlds: It does little to convince ordinary Egyptians that officials of the old regime will face justice for their crimes, and little to allay the generals’ fear of an outcome like the Iranian revolution of 1979, in which they would all end up swinging from the gallows.

This is not a formula for a successful democratic transition.

The two top contenders for this weekend’s presidential runoff are Marshall Ahmed Shafiq, who served as prime minister until Mubarak’s final hours in office, and Mohamed Morsi, a US-educated scientist and Muslim Brotherhood member who was little known to the public until he ended up at the center of the campaign. Neither man stands much chance of uniting the country, and if they’re not careful, they may even tear it apart.

In a quote to the Egyptian daily al-Ahram, Shafiq hailed Mubarak’s sentencing as proof that “no one is above the law,” in hopes of demonstrating his impartiality toward the military in which he served, while Morsi promised to keep Mubarak in jail “for eternity,” regardless of the court’s ruling.

If Shafiq wins the presidency, some revolutionaries say they would risk starting a second revolution. In a series of coordinated actions, unknown protesters have attacked several of his campaign offices and set one of them ablaze, and officials fear worse to come.

If Morsi wins, the generals of the ruling Supreme Council of the Armed Forces will have an no incentive to prevent the country from sliding into anarchy, until the public demands a candidate who can restore safety and security.

Of Egypt’s 50 million voters, only 46 percent went to the polls in the first round of voting, with many appearing to be holding out until the second round of voting next month. Though the Islamists and Mubarak apparatchiks garnered the most votes, 21 percent of voters channeled their frustration into support for the socialist Hamden Sabahi, an unlikely candidate backed by the liberal Mohamed ElBaradei. Former foreign minister Amr Moussa also won 11 percent, drawing almost exclusively on secular liberal voters.

Neither the military nor the Islamists can outmaneuver the other, which paradoxically forces both to appeal to the large and growing bloc of undecided voters, who have finally begun organizing.

As undesirable as Shafiq is to the reformers who hoped for a Vaclav Havel-style figure, he would likely make a better president, because he could assure the generals that they will benefit by going along with the democratic transition.

Nor would Shafiq’s victory cost the Muslim Brotherhood all its support. It would simply force the Islamists to win back the trust of the country’s secular political groups, which it abandoned in exchange for support from the generals, who enabled it to dominate the legislative elections.

Emboldened by their legislative victory, the Brotherhood sought to write the constitution that defines the powers of the president, and choose the man who filled the seat. This would have given them almost complete control of the country, but it cost them the support of all the non-Islamist parties, and finally the military.

While the elections have not produced a Havel, they have demonstrated that Egypt is more than just a military regime and a series of Islamist party. The country is simply too diverse for any political system that does not accept diversity and pluralism.

Paradoxically, if Shafiq wins, he will owe his success to the secular forces of the pro-democracy movement, and will thus be obliged to deliver on some democratic reforms. As the Brotherhood begins recalibrating, it will more than likely join other political groups in pushing Shafiq in the right direction.

For all the ugliness of the choices, there is cause for hope. Almost everyone thought Mubarak would die on the throne, but last February, the Egyptian people demonstrated for the first time in six decades that they could bring down the president. They can always take to the streets again, and the regime thus faces a check it never faced before.

That alone ensures that whoever wins the runoff, Egypt will not retreat into military dictatorship, nor descend into theocracy.

Khairi Abaza is a senior fellow at the Foundation for Defense of Democracies and a former official in Egypt’s secular liberal Wafd party.