Deposed Egyptian leader Hosni Mubarak could leave prison as early as Thursday after a court ruling that jolted a divided nation already in turmoil seven weeks after the army toppled Islamist President Mohammed Morsi, but he will be released to house arrest.

Convening on Wednesday at the Cairo prison where Mubarak is held, the court upheld a petition from his lawyer demanding the release of the man who ruled Egypt for 30 years until he was overthrown during the uprisings that swept the Arab world in early 2011.

Judicial and security sources said the court had ordered Mubarak's release. His lawyer, Fareed al-Deeb, confirmed this as he left Tora prison after the session. Asked when Mubarak would go free, he told Reuters: "Maybe tomorrow."

The prime minister's office said that Mubarak would be placed under house arrest. "In the context of the emergency law, the deputy military commander issued an order that Mohamed Hosni Mubarak should be put under house arrest," read a statement from the office.

The prosecutor overseeing the case said on Wednesday that Egypt's prosecutor will not appeal against the ruling ordering Mubarak's release. "The decision to release Mubarak issued today ... is final and the prosecution cannot appeal against it," Judge Ahmed el-Bahrawi said.

Mubarak, 85, 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.

The ailing former president probably has no political future. But many Egyptians would see his release as the rehabilitation of an old order that endured through six decades of military-backed rule - and even a reversal of the pro-democracy revolt that toppled him.

At least 900 people, including 100 soldiers and police, have been killed in a crackdown on Morsi's Muslim Brotherhood in the past week, making it Egypt's bloodiest civil episode in decades.

The United States and the European Union are both reviewing aid to Cairo in light of the bloodshed, but Saudi Arabia, a foe of the Brotherhood, has promised to make up any shortfall.

Mubarak is still being retried on charges of complicity in the killing of protesters during the revolt against him, but he has already served the maximum pre-trial detention in that case.

The court ruling removed the last legal ground for his imprisonment in connection with a corruption case, following a similar decision in another corruption case on Monday.

Mubarak's release might stir more turbulence in Egypt, where the army ousted Morsi, the country's first freely elected leader, on July 3, saying it was responding to the will of the people following vast protests demanding his removal.

The generals have installed an interim administration to oversee a roadmap they say will lead Egypt to back to democracy.

Gulf pressure

The authorities now portray their quarrel with the Brotherhood, Egypt's best-organized political force, as a fight against terrorism and are jailing its leaders, detaining the group's "general guide", Mohamed Badie, in Cairo on Tuesday.

Saudi Arabia and the United Arab Emirates, which along with Kuwait have promised Egypt $12 billion in aid since Morsi's ouster, have frowned on Mubarak's detention all along. Arab diplomats said the conservative Gulf monarchies 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 named, said the treatment of the former supreme military commander had "tarnished the army's image".

The United States, a close ally of Egypt since Cairo signed a peace treaty with Israel in 1979, said on Tuesday that the crackdown on protesters could influence U.S. aid. It denied reports it had already suspended assistance.

At issue is the future of about $1.23 million in U.S. military assistance and $241 million in economic aid to Egypt.

EU foreign ministers meet on Wednesday to discuss how the 28-nation bloc might use its economic power to promote an end to Egypt's conflict, in which it has sought to mediate.

They are likely to tread carefully, mixing expressions of concern over bloodshed with limited, if any, changes in a 5 billion euro ($6.7 billion) aid package promised last year to help foster the new democratic system, diplomats in Brussels said.

More arrests

Western nations were uneasy during Morsi's year in power, when he assumed extraordinary powers to ram through an Islamist-tinged constitution.

Washington has not denounced the army takeover as a "coup," which under U.S. law would force a suspension of aid. The ensuing bloodshed, however, has dismayed the West.

U.S. Senator John McCain, a former Republican presidential nominee who has emerged as a strong advocate of suspending aid, said: "The slaughter of hundred of Egyptians in the street is appalling to all of us.

"Now we should expect in return for our aid that the generals who are now running the country schedule a change in the constitution, schedule elections as soon as possible and the installation of a government that is representative of the people. The present government is representative of no one."

The arrest of Badie, the Brotherhood's leader, is part of a wave of detentions among the upper echelons of the organisation.

Murad Ali, a media adviser to the Brotherhood's political party, and Safwat Hegazy, a fiery preacher, were arrested while trying to flee the country, state media reported on Wednesday.

The Brotherhood said the crackdown would prove futile.

"The putschists think that arresting the leaders of the Muslim Brotherhood and marring their image in the media will make Egyptians bow and give in to the coup," it said.

"They have killed thousands, wounded thousands, arrested thousands but the (people) are continuing in their peaceful revolution, rejecting the coup and military rule."

Badie was charged in July with incitement to murder in connection with protests before Morsi's removal and is due to stand trial on August 25 along with his two deputies.

On Tuesday, the state prosecutor ordered him detained for 30 days on the charges of incitement to killing during anti-Mursi protests in November and demonstrations in Cairo last month.

Footage released to local media showed the bearded leader sitting grim-faced in a grey robe near a man with a rifle following his detention overnight on Tuesday - images that seemed intended to humiliate the Brotherhood chief.

The Islamist group, founded in 1928, used its organisational muscle to secure victory for Morsi in last year's presidential election. It says it has about a million members among Egypt's 85 million people, as well as offshoots across the Arab world.