CAIRO -- A court in Egypt has ordered that former President Hosni Mubarak, who has been detained on a variety of charges since his ouster in 2011, should be set free, according to state media and security officials on Monday, but it remained possible that the authorities would find a way to keep him in detention and his release did not appear imminent.
Egyptian state media reported that Mr. Mubarak would remain in custody for another two weeks under a previous judicial order before the authorities make a decision on his release. The outcome of their deliberations is likely to be read as a pivotal test of the new government installed by General Abdul-Fattah el-Sisi and its desire to replicate or repudiate Mr. Mubarak's rule.
The development threatened to inject a volatile new element into the standoff between the country's military and the Islamist supporters of the deposed President Mohamed Morsi, as Egypt entered the sixth day of a state of emergency following a bloody crackdown by the military in which hundreds of people have been killed.
It was unclear how Egyptians -- particularly those who have welcomed the military action against Mr. Morsi -- would respond to the release of a despised autocrat whose downfall united Mr. Mubarak's secular and Islamist foes. News of the legal maneuvers came at a time of sustained bloodletting.
Just in the past 24 hours, the Egyptian government has acknowledged that its security forces had killed 36 Islamists in its custody, while suspected militants were reported on Monday to have killed at least 24 police officers and wounded 3 others in an attack on their minibuses in the restive northern Sinai region.
Mr. Mubarak, 85, faces an array of legal challenges including allegations of corruption and a retrial on charges of complicity in the murder of protesters whose revolt forced his ouster in February, 2011.
On Monday, Mr. Mubarak's lawyer, Farid el-Deeb, said a court had ordered his release and he might be freed this week. But there was no official confirmation from the military-backed interim government that Mr. Mubarak would be set free.
News reports said that the ambush on Monday morning had occurred in a village near the border town of Rafah. It was the latest in a series of attacks in Sinai since the military forced Mr. Morsi from office on July 3.
The attackers were initially depicted as Islamist militants firing rocket-propelled grenades at the police minibuses.
But there was some confusion, with later reports quoting officials who put the death toll at 25. Officials were also quoted as saying that the officers had been forced from their minibuses, told to lie on the ground and then shot to death. There was no immediate official confirmation of the events.
The Sinai Peninsula borders the Gaza Strip and Israel, which is planning to intensify a diplomatic campaign urging Europe and the United States to support the military-backed government in Egypt despite its deadly crackdown on Islamist protesters, according to a senior Israeli official involved in the effort.
Israeli ambassadors in Washington, London, Paris, Berlin, Brussels and other capitals planned to advance the argument that the military was the only hope to prevent further chaos in Cairo. On another diplomatic front, ambassadors from the 28-member European Union planned to meet on Monday to review the bloc's relationship with Egypt, confronting a similar question of whether stability and security outweigh considerations relating to human rights and democracy.
In a radio interview on Monday, William Hague, the British foreign secretary, said he did not accept that outsiders were powerless to influence events. "But we have to do our best to promote democratic institutions, to promote political dialogue and to keep faith with the majority of Egyptians who just want a free and stable and prosperous country," he told the BBC.
"What we've done in Britain so far is that we have suspended projects with the Egyptian security forces. We have revoked a number of export licenses, and I think then among the European countries we should review together how we try to aid Egypt, what aid and assistance we give to Egypt in the future," he said. He added, "Foreign policy is often about striking the right balance."
He described the current crisis as bleak. "I think it will take years, maybe decades, to play out," he said, "and through that we have to keep our nerve in clearly supporting democracy, democratic institutions, promoting dialogue and there will be many setbacks in doing that and we should not be surprised when they take place."
On Sunday, there appeared to be a pause in the street battles that since Wednesday have claimed more than 1,000 lives, most of them Islamists and their supporters gunned down by security forces. The Islamists took measures on Sunday to avoid further confrontations, including canceling several protests over the military's ouster of a democratically elected Islamist-led government.
While confirming the killings of the detainees on Sunday, the Ministry of the Interior said the deaths were the consequence of an escape attempt by Islamist prisoners. But officials of the main Islamist movement, the Muslim Brotherhood, described the deaths as "assassinations" and said that the victims, which it said numbered 52, had been shot and tear-gassed through the windows of a locked prison van.
The killings were the latest indication that Egypt is careering into uncharted territory, with neither side willing to back down. Egyptians are increasingly split over the way forward and there is no obvious political solution in sight. The government is considering banning the Brotherhood, which might force the group underground but would not unravel it from the fabric of society it has been part of for eight decades.
Foreign governments also remain divided over the increasingly bloody showdown. American officials said they had taken preliminary steps to withhold financial aid to the Egyptian government, though not crucial military aid, and the European Union said Sunday that the interim government bore the responsibility for bringing the violence to an end.
But the Egyptian military retains the support of the oil-rich states of the Persian Gulf, especially Saudi Arabia and the United Arab Emirates, which have pledged billions in aid to the new government.
Although it appeared that security forces were more restrained on Sunday -- with no immediate reports of killings in the streets -- General Sisi, the country's military leader, spoke out on national television in defiant and uncompromising tones, condemning the Islamists again as "terrorists" but promising to restore democracy to the country.
The government has been pursuing a relentless campaign to paint the Islamists as a threat, and it has increasingly lashed out at journalists who do not echo that line, especially the foreign news media.
Acknowledging but rejecting the widespread international criticism of the security force's actions, the general said that "citizens invited the armed forces to deal with terrorism, which was a message to the world and the foreign media, who denied millions of Egyptians their free will and their true desire to change."
The Muslim Brotherhood had announced that it would stage nine protest marches in and around Cairo on Sunday as part of its "week of departure" campaign that began Friday to protest the military's deposing of the country's first democratically elected president, Mr. Morsi.
All but three of the marches were canceled, and even those that continued were rerouted to avoid snipers who were waiting ahead, along with bands of government supporters, the police and the military, some in tanks. The authorities, too, appeared to avoid aggressively enforcing martial law provisions, including a 7 p.m. curfew, that would have led to clashes with the protesters.
Protesters who gathered at the Al Rayyan mosque in the Maadi area of Cairo had aimed to march from there to the Constitutional Court, Egypt's supreme court. The chief justice, Adli Mansour, has been appointed interim president by the country's military rulers.
Marching in the 100-degree late afternoon heat, the protesters were fatalistic about the threats they faced. Mohammad Abdel Tawab, who said his brother was killed Friday at Ramses Square, had heard the reports of pro-government snipers and gangs ahead. "They will kill us, I know, everybody knows, but it doesn't matter," he said.
Protest leaders, however, were more cautious and rerouted the march at the last moment to avoid confrontations.
There were scant details on the prison killings on Sunday, and no explanation for why the victims were inside a prison van and had reportedly taken a prison official hostage.
The Ministry of the Interior issued conflicting and confusing accounts, at one point claiming the prisoners had taken a guard hostage, then saying militants had attacked the prison van to free the prisoners, who were killed in the process, and then saying tear gas being used to suppress the escape had caused the prisoners to suffocate. Later, the ministry claimed the deaths had happened in the prison, not in the van.
David D. Kirkpatrick and Rod Nordland reported from Cairo and Alan Cowell from London. Mayy El Sheikh and Kareem Fahim and contributed reporting from Cairo.
This article originally appeared in The New York Times.