The officials said there were no longer any grounds to hold the 85-year-old former autocrat because of the expiration of a two-year legal limit for holding an individual in custody pending a final verdict.
Mubarak has been in detention since April 2011. He was found guilty and sentenced to life in prison in June last year for his failure to stop the killing of some 900 protesters in the 18-day uprising against his rule. His sentence was overturned on appeal and he is now being retried, along with his security chief and six top police commanders.
Monday's stunning announcement came as security forces said suspected Islamic militants ambushed two mini-buses carrying off-duty policemen in Egypt's Sinai Peninsula, forcing the men out onto the pavement and shooting 25 of them dead. The brazen daylight attack deepened the turmoil roiling the country and underscored the volatility of the strategic region.
Monday's killings, which took place near the border town of Rafah in northern Sinai, came a day after security forces killed 36 detainees during a riot on a prison-bound truck convoy north of Cairo. In all, nearly 1,000 people have been killed in violence between security forces and supporters of ousted President Mohammed Morsi since last Wednesday. The government has ordered an investigation into their deaths.
A few hours after the attack near Rafah, suspected militants shot to death a police major as he stood guard outside a bank in the city of el-Arish, also in northern Sinai, security officials said.
Tensions in Egypt have soared since the army ousted Morsi, Mubarak's successor, in a July 3 coup following days of protests by millions of Egyptians demanding the Islamist president leave and accusing him of abusing his powers.
But Morsi's supporters have fought back, staging demonstrations demanding that he be reinstated and denouncing the military coup.
On Wednesday, the military raided two protest camps of Morsi's supporters in Cairo, killing hundreds of people and triggering the current wave of violence.
Gen. Abdel-Fattah el-Sissi, the country's military chief, said Sunday that the crackdown, followed by a state of emergency and a nighttime curfew imposed in Cairo and several other flashpoint provinces, is needed to protect the country from "civil war." El-Sissi has vowed the military would stand firm in the face of the rising violence but also called for the inclusion of Islamists in the post-Morsi political process.
Sinai, a strategic region bordering the Gaza Strip and Israel, has seen almost daily attacks since Morsi's ouster - leading many to link the militants there to the Muslim Brotherhood, the Islamist group from which Morsi hails.
Egyptian military and security forces have been engaged in a long-running battle against militants in the northern half of the peninsula.
Al-Qaida-linked fighters, some of whom consider Morsi's Brotherhood to be too moderate, and tribesmen have used the area for smuggling and other criminal activity for years and have on occasion fired rockets into Israel and staged cross-border attacks. A year ago, 16 Egyptian border guards were slain in Sinai near the borders with Gaza and Israel in a yet unresolved attack that is widely blamed on militants.
In Monday's attack, the officials said the policemen were in civilian clothes. There was no immediate claim of responsibility for the attack, which also left two policemen wounded.
The officials, who spoke on condition of anonymity because they were not authorized to talk to the media, initially said the policemen were killed when the militants fired rocket-propelled grenades at the two minibuses. Such confusion over details in the immediate aftermath of attacks is common.
The killings on the prison convoy Sunday came as police fired tear gas to free a prison guard from rioting detainees. The detainees, who were rounded up during clashes over the past couple of days in Cairo, had managed to capture a police officer inside the truck, security officials said. The truck was part of a prison truck convoy of some 600 prisoners heading to Abu Zaabal prison in northern Egypt.
Security forces fired tear gas into the truck in efforts to free the badly beaten officer, the officials said, adding that the people killed died from suffocation. Those officials also spoke on condition of anonymity because they were not authorized to speak to journalists.
However, the officials' version of events contradicted reports about the incident carried by state media. The official website of state television reported that the deaths took place after security forces clashed with militants near the prison and detainees came under fire while trying to escape. The official MENA state news agency also said the trucks came under attack from gunmen.
State media also said those killed and the gunmen belonged to the Brotherhood. The officials who spoke to AP said some of the detainees belonged to the Brotherhood, while others didn't. The differences in the accounts could not be immediately reconciled.
On Monday, the government ordered an inquiry into the deaths, which it blamed on armed men allegedly trying to help the 600 Brotherhood detainees escape. It gave no details.
The Brotherhood said in a statement that it blamed the military chief, el-Sissi, and Interior Minister Mohammed Ibrahim who is in charge of the police, for Sunday's killings. The group also called for an international inquiry into the deaths. Amnesty International demanded a "full, impartial and effective" probe into the events, the London-based group said in a statement.
The judiciary officials, speaking on condition of anonymity because they were not authorized to talk to the media, said a court on Monday ordered Mubarak's release in a corruption case that alleged he and his two sons embezzled funds for presidential palaces. His sons will remain in custody because they face other cases against them.
Monday's order, along with the fact that Mubarak had previously been ordered released in two other cases against him - the killing of the protesters and a case related to illegal earnings - opened the possibility of freedom for the former president.
Mubarak is also facing trial for alleged acceptance of presents from state newspapers but has already repaid their value. His defense team has submitted a petition for his release in connection with the presents and a ruling is expected later this week.
Along with the state of emergency imposed after Wednesday's crackdown on the pro-Morsi sit-ins in Cairo and ensuing street clashes across the country, the military-backed interim government has also begun taking harsher measures to cripple the Brotherhood.
Security forces arrested hundreds of Muslim Brotherhood members early Sunday in raids on their homes in different cities, aimed at disrupting planned rallies to support Morsi. The Cabinet also held an emergency meeting to consider banning the group.
A possible ban - which authorities say would be implemented over the group's use of violence - would be a repeat of the decades-long struggle between the state and the Brotherhood. It also would drain the group's financial resources and allow for mass arrests of its members. That likely would diminish the chances of a negotiated solution to the crisis and push the group again underground.
The Brotherhood has shown no signs of backing down though.
It held protests Sunday under the banner of an "anti-coup alliance," though many appeared smaller in scale than others held in recent days. In the coastal city of Alexandria, protesters clashed with residents. In the southern city of Assiut, security forces fired tear gas to disperse hundreds rallying in front of a mosque.
"They think they can end the movement," said Muslim Brotherhood senior member Saad Emara. "The more killings, the more people join us."
However, the government blames Islamists for series of attacks on churches and police stations, increasing public anger against the group.
In his first public appearance since last Wednesday, el-Sissi spoke at length in an hour-long speech Sunday about the motives behind ousting Morsi. The general said the Islamist president exploited democracy to monopolize power. He again said the military's action "protected Egyptians from civil war," despite the ongoing violence on the streets.
"We will not stand by silently watching the destruction of the country and the people or the torching the nation and terrorizing the citizens," el-Sissi said in a speech aired on state television. "I am not threatening anyone ... If the goal is to destroy the country and the people, no!"
Morsi is also currently in custody, held incommunicado at an undisclosed location since his July 3 ouster.
Also on Monday, the European Union, which last year pledged a combined 5 billion euros ($6.7 billion) in loans and aid for Egypt, said it would hold an emergency meeting Wednesday to forge a response to the recent violence and discuss whether to halt aid programs and suspend arms shipments.
A day earlier, top EU officials said the bloc will "urgently review" its relations with the country. While the EU lacks the military muscle that gives the U.S. a special position in dealing with Egypt, European nations are a major source of aid, loans, business and tourists.
Associated Press writer Ashraf Sweilam contributed to this report from el-Arish, Egypt.