The Egyptian president has ordered the powerful head of the army and defence minister, Field Marshal Hussein Tantawi, and several senior generals into retirement and canceled constitutional amendments issued by the military restricting presidential powers.
Mohamed Morsi announced through a spokesman on Sunday the dismissal of Tantawi and his appointment as a presidential adviser.
According to state television, Abdul-Fatah al-Sessi would replace Tantawi as defence minister and the general commander of the army.
Morsi also sent into retirement the chief of army staff, General Sami Anan, and appointed him as a presidential adviser.
Lieutenant-General Sidki Sayed Ahmed was named as Anan's replacement.
Morsi further appointed a senior judge, Mahmoud Mekki, as vice-president. All decisions are effective immediately.
Thousands of Egyptians celebrated the announcement on Sunday night in Cairo’s Tahrir Square that played home to the protests that ousted Mubarak.
"The people support the president's decision," the crowd chanted.
Others mocked Tantawi's departure, presented officially as a retirement.
"Marshal, tell the truth, did Morsi fire you?" they said.
Al Jazeera’s Rawya Rageh, reporting from Cairo, said: "The country may be without a constitution, but there are constitutional declarations that specify the job description of the president, and it is perfectly within the realm of his authority to hire and fire senior government officials."
"But I guess the talk about all of this is emanating from the fact that this was such a surprising and bold move," she said.
"Morsi who did not want to defy the military initially, seized on the opportunity of the border attack to end the political career of one of the longest serving military men in the country.
"But whether it was about political score or really an issue of accountability, irrespective of the motives, this indeed was a political earthquake."
"After all, both Tantawi and Anan, the two most powerful members of the Supreme Council of the Armed Forces (SCAF), long appeared invincible - both during the period SCAF took control over the country and even after President Morsi’s election in June," she said.
Besides Tantawi and Anan, Morsi also ordered the retirement of the commanders of the navy, air defence and air force.
The latest moves are seen as escalating the power struggle between Morsi, who took office on June 30, and the military.
In an address to the nation on Sunday evening, Morsi said that his move was not directed at individuals.
"The decisions I took today were not meant ever to target certain persons, nor did I intend to embarrass institutions, nor was my aim to narrow freedoms," he said.
"I did not mean to send a negative message about anyone, but my aim was the benefit of this nation and its people."
Morsi praised the work of the armed forces, saying his decision would free them to focus on their professional tasks.
Tantawi was the head of SCAF, which ruled the country after Hosni Mubarak was toppled as president in February 2011.
He was defence minister for nearly two decades under Mubarak.
Morsi, from the Muslim Brotherhood, and his Islamist allies did not hide their displeasure with the amendments issued by the military in mid-June curtailing the president's role and granting the army massive powers, including legislative control.
Earlier this week, Morsi sacked the head of the intelligence service.
The retired navy commander, Lieutenant-General Mohan Mameesh, was named as chairman of the Suez Canal, the strategic waterway linking the Red Sea and the Mediterranean and a major source of revenues for the country.
Earlier, Al Jazeera's correspondent, Sherine Tadros, reporting from Cairo, said: "There will be a lot of questions asked, especially if Morsi is able to do this.
"In the coming hours, we will find out how this decision came about. All of this has happened very fast, and it was unexpected."