The Egyptian army toppled Islamist President Mohamed Morsi on Wednesday after a week of bloodshed that killed nearly 50 people as millions took to the streets to demand an end to his turbulent single year of rule.
The announcement, made on state television by Morsi's own defence minister, armed forces chief General Abdel Fattah al-Sisi, drew a rapturous welcome from the protesters who have camped out on the streets of Cairo for days.
Sisi also announced a freezing of the Islamist-drafted constitution and early presidential elections.
Thousands of people immediately took to the streets of the capital to celebrate, cheering, whistling, letting off firecrackers, and honking car horns in joyous scenes.
But Morsi's office rejected the move as "illegal" and called on Egyptians to peacefully resist the "coup".
Morsi, Egypt's first freely elected president, came under massive pressure in the run-up to Sunday's anniversary of his maiden year in office, with his opponents accusing him of failing the 2011 revolution by concentrating power in Islamist hands.
The embattled 62-year-old proposed a "consensus government" as a way out of the country's worst crisis since the 2011 uprising ended three decades of authoritarian rule by Hosni Mubarak.
But the United States urged Morsi to "do more" as a military deadline passed for him to meet the demands of the people following a week of bloody unrest during mass protests calling for him to quit.
The advice came too late, however, as the army said the head of the Supreme Constitutional Court, Adly al-Mansour, a previously little known judge, would become the new leader of the Arab world's most populous country.
Opposition leader Mohamed ElBaradei, the UN nuclear watchdog chief, and the heads of the Coptic Church and Al-Azhar, Sunni Islam's highest seat of learning, sat alongside the armed forces chief as he announced Morsi's overthrow on state television.
The choreography was designed to show broad civilian support for the military's move to topple Morsi, Egypt's first freely elected leader, dashing the hopes of supporters who had seen his elevation to the presidency after years underground as one of the key achievements of the 2011 revolution.
Morsi's camp had earlier denounced the army's intervention as a coup.
"For the sake of Egypt and for historical accuracy, let's call what is happening by its real name: military coup," Essam al-Haddad, Morsi's national security adviser, said in a statement on Facebook.
As tension mounted and crowds poured onto the streets to demand Morsi's resignation, Haddad said: "As I write these lines I am fully aware that these may be the last lines I get to post on this page."
AFP correspondents reported seeing dozens of armoured personnel carriers heading towards Islamist gatherings at Cairo University, Heliopolis and Nasr City.
But in Cairo's Tahrir Square, the security forces looked on as tens of thousands of anti-Morsi protesters rallied in a demonstration that dwarfed that of the embattled president's supporters in Nasr City, on the opposite side of town.
"Come here O Sisi, Morsi isn't my president," the flag-waving protesters chanted in the square, referring to the army chief.
The crowd swelled at nightfall, after a scorching day that saw police officers hand out water to the demonstrators in the middle of Tahrir, epicentre of the 2011 uprising that ended three decades of authoritarian rule by Hosni Mubarak.
The powerful military had issued a 48-hour deadline on Monday for Morsi to meet the "people's demands", a day after millions of protesters took to the streets across the troubled country calling for him to resign.
Thousands of people also gathered in Nasr City in a show of support for Morsi, despite an attack that killed 16 of them and injured 200 overnight.
That spate of bloodletting took to almost 50 the number of people killed in Egypt since the latest crisis flared a week ago ahead of Sunday's anniversary of Morsi's swearing-in.
Opponents accuse Morsi of having betrayed the revolution by concentrating power in Islamist hands and of sending the economy into freefall. His supporters said he inherited many problems, and that he should be allowed to see out his mandate, which had been supposed to run until 2016.
In a late night speech on Tuesday, a defiant Morsi said he had been freely elected more than a year ago and intended to carry on his duties. The only alternative was more bloodshed.
Upping the stakes, senior armed forces commanders meeting on Wednesday swore to defend Egypt with their lives, a source close to the military told AFP.
"We swear to God that we will sacrifice our blood for Egypt and its people against all terrorists, extremists and the ignorant," they declared in an oath led by General Sisi, the source said.
Egypt's press had predicted Wednesday would be the day of Morsi's departure.
"Today: Ouster or Resignation," splashed the state-owned mass circulation Al-Ahram newspaper. "The End," declared the independent Al-Watan.
Aside from Tahrir, Nasr City and a few other areas, Cairo's streets were unusually quiet, with many choosing to stay home over fears of more violence.
"The Islamists declared war on the rest of the population yesterday. I'm very scared," said resident Soha Abdelrahman.
All eyes were on the military, after Al-Ahram reported details of the its roadmap for the future.
The plan provides for an interim administration, of up to one year, which would include the head of the supreme constitutional court and a senior army figure.
The constitution, controversially approved by Morsi's Islamist allies in December, would be suspended for up to 12 months while a new one was drawn up and put to a referendum, before presidential and parliamentary elections.