Egypt formally detained Mohamed Morsi on Friday for allegedly abetting militants in murdering policemen and staging prison escapes, as clashes during massive rallies by his opponents and loyalists killed five people.
The deposed Islamist president's detention, under a court order for a renewable 15 days, further raised tensions as those applauding the decision and those demanding his reinstatement flooded parts of Cairo and other cities.
Five people were killed in the Mediterranean city of Alexandria in clashes between the rival protesters, despite a massive police and military deployment, the official MENA news agency reported.
The Arab world's most populous country has been rocked by violence that killed some 200 people since the army ousted Morsi on July 3, many in clashes between his supporters and opponents, and in militant attacks in the Sinai peninsula.
At least 72 people were wounded in the Alexandria violence, in which riot police intervened. Ten people were wounded in clashes in Cairo, medics and the health ministry said.
The overwhelming number of Friday's marches remained peaceful, however, with tens of thousands of Morsi supporters gathering in a north Cairo square.
Hundreds of thousands of anti-Morsi protesters gathered in Cairo's Tahrir Square and around the Itihadiya presidential palace in response to a call from army chief General Abdel Fattah al-Sisi for Egyptians to show their support for a security clampdown on "terrorism".
A spokesman for army-installed interim president Adly Mansour said the numbers in Tahrir "affirmed the rejection of terrorism," MENA said.
Tens of thousands of army supporters also rallied outside the presidential palace, waving Egyptian flags and holding posters of Sisi who was Morsi's defence minister before ousting him.
A leader of Morsi's Muslim Brotherhood, Essam al-Erian, said in a statement they would respond to his detention with "peaceful marches".
The accusations against Morsi include conspiring with Palestinian Hamas militants in attacks that killed policemen and staging prison breaks during the 2011 revolt that ousted president Hosni Mubarak.
Morsi had been detained with other Brotherhood leaders overnight on January 27, 2011, hours after the Islamist group said it would join the revolt against Mubarak. They later escaped from prison.
He is also accused of "premeditated murder of some prisoners, officers and soldiers, and kidnapping officers and soldiers," MENA said.
Morsi is also suspected of conspiring to "storm prisons and destroy them... allowing prisoners to escape, including himself".
Detention orders of the type issued by the court are usually followed by moving a suspect to prison. The military has so far kept Morsi's whereabouts secret to avoid attracting protests by his supporters.
Gehad El-Haddad, a Brotherhood spokesman, denounced the detention order, saying Mubarak's regime was "signalling 'we're back in full force'".
A court had on June 23 said Hamas militants facilitated the escape of prisoners during the tumultuous 18-day uprising that forced out Mubarak.
Hamas, an offshoot of the Muslim Brotherhood which supports the Gaza militant group's fight against Israel, also denounced Morsi's detention.
"Hamas condemns this move since it is based on the premise that the Hamas movement is hostile," spokesman Sami Abu Zuhri told AFP.
Morsi's election victory in June 2012 had been hailed by Hamas as a triumph for Islamists.
He helped negotiate a truce to halt fighting between Israel and Hamas in November on favourable terms for the Islamists, but also oversaw the closing of smuggling tunnels to Gaza.
The military has reportedly given Morsi's backers until the end of Friday to end sit-in protests they began after the army deposed him.
Egypt's army has said there would be no reneging on a roadmap to fresh elections next year, drawn by the interim government installed after Morsi's ouster.
The Brotherhood and allied Islamist groups have rejected the interim government and vowed to press their protests until Morsi is reinstated.
Western nations are watching the crisis in Egypt with growing unease, fearing the military may be angling for a prolonged power grab.
The United States has decided not to label the army's overthrow of Morsi a "coup", a move that would trigger an automatic freeze of some $1.5 billion (€1.1 billion) in aid, a US official said.
But Washington did finally send the interim leaders a veiled warning on Wednesday by suspending the delivery of four promised F16 fighter jets.
"The interim government's strategy clearly consists of politically sidelining the Muslim Brotherhood until the elections," said German Middle East expert Michael Lueders.
London-based rights group Amnesty International criticised Sisi's call for rallies.
"Given the security forces' routine use of excessive force, such a move is likely to lead to yet more unlawful killings," said Hassiba Hadj Sahraoui, Amnesty's deputy director of its Middle East and North Africa programme.