Progress from autocracy to democracy has been complicated by tensions, divisions and violence at every turn

Egypt, a Cairo wit quipped recently, is "lost in transition". The serious point is that although Hosni Mubarak stepped down in February 2011, the country's progress from autocracy to democracy has been halting and complicated by tensions, divisions and violence at every turn.

Now, just two days before the runoff round of an already polarised presidential election, an extraordinary twist has created profound new uncertainties. The most dramatic interpretation is that it spells a decisive victory for the forces of counter-revolution. "It is like The Empire Strikes Back in the Star Wars saga," commented the popular blogger Zeinobia. Others denounced it furiously as a judicial coup.

It is not surprising that the constitutional court decided that Ahmed Shafiq, Mubarak's last prime minister, is eligible for the race, having ruled against a "political isolation" law that would have prevented him seeking office as a member of the old regime.

The judges, appointed under Mubarak, are widely seen as representative of the "deep state" that has survived the convulsions of the Egyptian chapter of the Arab spring to manoeuvre, manipulate – and retain power – behind the scenes.

Shafiq's battle against Mohamed Morsi, the candidate of the Muslim Brotherhood's Freedom and Justice party, has been dubbed a "nightmare scenario" by Egyptian commentators who see it as a throwback to the bad old days when the military-backed presidency was ranged against the world's oldest Islamist movement, with little else in the way of independent political forces between them.

But the court's second ruling is far more volatile in its implications. The dissolution of the entire parliament – not just byelections for the third of MPs deemed to have been improperly elected – means that the Islamists who dominate it, from the Brotherhood and the hardline Salafi Nur party, will feel disenfranchised and cry foul.

Given that parliament has performed terribly, their prospects for re-election will clearly be damaged. The silver lining for worried Egyptian liberals is that could make badly needed space for secular independents such as Mohamed ElBaradei and the failed presidential candidate Amr Moussa.

Shafiq's triumphant tone sounded uncomfortably like a claim of victory, so those who scorn him as a fuloul or "remnant" of the old order will feel vindicated in their darkest suspicions. The Supreme Council of the Armed Forces (Scaf), made up of ageing generals who served their commander-in -chief, Mubarak, loyally until the very end, has been confirmed in its domination of a fragmented political scene.

"How many Scaf generals does it take to change a lightbulb?" asked one cynical Arab blogger. "None: they pretend to change it but after a while they put back the old one."

The rulings pile confusion upon chaos: it was already clear that whoever is elected president would take office without knowing his powers because a new constitution has yet to be written. Now, in the absence of a parliament, Mubarak's successor will be sworn in by generals, not MPs. It is not going to be an auspicious beginning to what has been billed as Egypt's "second republic" – replacing the one founded by Gamal Abdel-Nasser when he and his fellow officers overthrew the monarchy in 1952.

"Egypt's transition," commented the veteran US scholar Nathan Brown, "may well be from military dictatorship to presidential dictatorship."

What happens next is anyone's guess, though it would be surprising if there were not protests – the reflex action of frustrated revolutionaries who see the hopes of Tahrir Square fading fast – and a harsh response by the army and police. What is certain is that Egypt's transition just got a lot messier.