An Egyptian court ordered the release of former president Hosni Mubarak today, a judicial and a security source said, meaning he could leave prison later in the day as there is no longer any legal grounds for his detention.
Mubarak (85) is being retried on charges of ordering the killing of protesters during the 2011 uprising that led to his downfall.
However, he has already served out the maximum amount of pretrial detention permitted in that case.
Mubarak was sentenced to life in prison last year for failing to prevent the killing of demonstrators. But a court accepted his appeal earlier this year and ordered a retrial.
Egypt is in turmoil seven weeks after the army toppled Mubarak's elected successor Mohamed Morsi.
At least 900 people, including 100 soldiers and police, have been killed in a crackdown on Morsi's Muslim Brotherhood in the past week, the bloodiest civil unrest in Egypt's modern history.
The United States and the European Union are both reviewing aid to Egypt in light of the bloodshed, but Saudi Arabia, a foe of the Brotherhood, has promised to make up any shortfall.
Although at 85 Mubarak probably has no political future, his release would be seen by many in the Arab world as rehabilitation of an old order of six decades of rule by military men - and even a reversal of the 2011 pro-democracy uprising that brought him down.
The generals ousted Morsi, Egypt’s first freely elected leader, on July 3rd, saying they were responding to the will of the people following vast demonstrations demanding his removal.
They have installed an interim administration to oversee a roadmap they say will lead Egypt back to democracy.
The authorities now portray their quarrel with the Muslim Brotherhood, Egypt's best-organised political force, as a fight against terrorism and are jailing its leaders, including its "general guide", Mohamed Badie, detained in Cairo on yesterday.
Saudi Arabia and the United Arab Emirates, which along with Kuwait have promised Egypt $12 billion in aid since Mursi’s overthrow, have frowned on Mubarak’s detention all along.
Arab diplomats said the conservative Gulf states had lobbied for the release of a man they once valued as a strong regional ally.
Mubarak’s trial, when he appeared in a courtroom cage, and his jailing also affronted some Egyptian officers. One colonel, who asked not to be identified, said the treatment of the former supreme military commander had “tarnished the army’s image”.