Mursi's spokesman called it a "sovereign" decision by the head of state, and aimed at "pumping new blood" into an army that has shown signs of hoping to control the novice president.
The move sidelined Hussein Tantawi – a field marshal who served former President Hosni Mubarak as defence minister and whose continued presence cast a shadow of military rule over the new democracy – and military chief of staff Sami Enan. Mursi also scrapped the army’s constitutional declaration, which gave the military strong powers over the secular presidency.
Mursi took them by surprise
It was not clear how far the generals, members of the Supreme Council of the Armed Forces (SCAF), actually consented to a move that reveals a reordering of Egypt's political forces as the country waits for a new constitution, shifting more powers towards Mursi and his long-suppressed Muslim Brotherhood.
Thousands of Islamist supporters gathered in Cairo's Tahrir Square and other cities to back Mursi's decision. "President of the republic, your decree gets 100%," some chanted.
Tantawi, after serving Mubarak as a minister for 20 years, helped ease the ageing dictator out of office on 11 February 2011 in the face of the mass street protests of the Arab Spring.
An embarrassing debacle for the army on the border with Israel, where 16 Egyptian troops were killed by Islamist militants a week ago, may have given Mursi the opening he needed to step up the pace in rolling back the military's influence.
Scene set for confrontation with court
Mursi appointed General Abdel Fattah al-Sisi, 57, from military intelligence, as a replacement for Tantawi. Enan was replaced General Sidki Sobhi, 56.
Both those pushed into retirement, whose positions may have been weakened by the border debacle last week in the Sinai desert, were appointed as advisors to the president.
By scrapping the army's constitutional declaration, Mursi can also take on the legislative powers the generals had sought to keep for themselves in the absence of a parliament. In June, the military council, backed by judges, dissolved the Islamist-led assembly elected in January - a move Mursi has challenged.
Mursi has also set the scene for a possible confrontation with the supreme constitutional court, which may declare his handling of the constitutional declaration invalid.