Hosni Mubarak, the former Egyptian president, is to be freed after a Cairo court ordered his release. Prosecutors said they would not appeal, so Mubarak could be out of prison as soon as Thursday, Egyptian media reported, although he will not be allowed to leave the country.

Mubarak will then be put under house arrest, the prime minister's office said. The decision was authorised under Egypt's emergency law recently enacted under a security crackdown on Islamists, it added. Citing a security source, the state news agency said Mubarak would "likely" be taken to one of the state's vital installations or one of two military hospitals where he will be guarded under heavy security.

The decision comes at a highly volatile moment after hundreds of Islamist protesters were killed last week and the military-backed government continues its crackdown on the Muslim Brotherhood.

Jubilant supporters quickly launched a Facebook page to promote Mubarak's candidacy for the presidency next year.

Overthrown in January 2011 at one of the early high points of the Arab spring, Mubarak had spent the last two years in detention and could be detained again. But his release is loaded with symbolism about the parlous state of Egypt and fading hopes for peaceful political change across the wider region – graphically underlined by the latest carnage in Syria.

Mubarak remains on trial for murder over the deaths of more than 800 protesters during the uprising against him. But after a separate corruption charge was settled this week, the time limit for him to remain in custody had expired.

Egyptians angered at the army's removal of the democratically elected but deeply unpopular president, Mohamed Morsi, after mass protests last month will be infuriated by the coincidence of his unelected and autocratic predecessor walking free. "His release will cause chaos," warned legal expert Nasser Amin. "It will be used by Islamists as proof of the return of the old regime."

Egyptian officials had acknowledged privately that freeing Mubarak in this highly charged atmosphere was likely to fuel tensions. "The government knows that if Mubarak is freed there will be public outrage," said Mohamed Abolghar, head of the Egyptian Social Democratic party. "But a court decision is a court decision."

By keeping Mubarak under house arrest, Egyptian leaders may be trying to show they will not be too lenient with him to avoid angering the many Egyptians who held mass protests that led to the end of his rule in 2011. The hearing that produced Wednesday's ruling was held in Tora prison, where Mubarak, 85 and in poor health, has spent most of his detention.

He was given a life sentence last year for failing to stop the killing of protesters but that was overturned on appeal and he is being retried. He also faces other corruption charges but no other trial dates have been set.

Most Egyptians have stopped following the legal twists and turns of the case but the significance and timing of this decision is still stunning. Saudi Arabia, dismayed that the US had abandoned Mubarak, is said to have been lobbying hard behind the scenes to have him freed. The Saudis helped put together a $12bn (£7.5bn) aid package for Egypt after Morsi was deposed last month.

Sherief Gaber, of the Mosireen collective, a pro-revolutionary group, said: "The symbolism is clear coming from a completely revanchist judiciary, that even the symbolic victory of imprisoning Mubarak will be revoked, that the counter-revolution and the old regime are feeling empowered and petty.

"The judiciary and the police are the two institutions that are most entrenched and most a part of the old regime; they were on their heels for a while, but using the bogeymen of the Muslim Brotherhood and people's fear and exhaustion, they're just doing whatever they feel like to be personally spiteful and cruel even.

"Mubarak after all was just a symbol, and we knew that the regime was much bigger and had not yet fallen but needed to (and still needs to)."

The news prompted bitter reflections about the state of the Arab world two-and-a-half years after the uprisings in Egypt, Syria, Tunisia and Yemen.

"Give it five months and Mubarak, Assad, Ben Ali and Ali Saleh will hold a summit for the sake of good ol' days," tweeted Hassan Hassan, a Syrian commentator.

The Egyptian government has signalled defiance in the face of international criticism of the recent killings and ongoing moves to crush the Brotherhood.

EU foreign ministers met in Brussels in emergency session to review aid to Egypt worth €6.7bn. They suspended exports of weapons and goods that could be used for internal repression but did not halt aid programmes for fear of hurting ordinary Egyptians. They called on the military authorities and Morsi's Muslim Brotherhood movement to resume negotiations to avoid further bloodshed.

The US made clear on Tuesday that it has not made any firm decisions to cut assistance. "If there is a price to pay we will pay it," said one Egyptian official. "There is a frenzy of national feeling and people are defiant. It's not really about money. These are relationships we have invested in for 40 years. If the Europeans and Americans disengage Egypt will carry on. But it is too important to ignore."

"To hell with US aid, foreign intervention, terrorism and foreign financing," the al-Umal newspaper said in a front-page headline on Tuesday. "We would rather starve than submit to foreign tutelage and American humiliation."

Tamarrod, the protest movement which mobilised mass support for Morsi's removal, has also called for an end to US aid and to the 1979 peace treaty with Israel.

The government in Cairo is pinning its hopes on promises from the Saudis and other conservative Gulf states to compensate Egypt for any financial losses due to punitive action by the US or Europe.Two more Islamist leaders were reported to have been detained on Wednesday after the arrest of the Brotherhood's leader or guide, Mohamed Badie, on Tuesday. Safwat Hegazy, an outspoken preacher, was captured while trying to cross theborder to Libya. Mourad Ali, a spokesman for the Brotherhood's Freedom and Justice party, was detained at Cairo airport.