Egypt's nascent democracy moved a step closer to political maturity over the weekend when President Mohamed Morsi unexpectedly forced the retirement of several senior generals on the military council that has ruled the country since the fall of former President Hosni Mubarak's last year. On Sunday, Mr. Morsi sacked his defense minister, army chief of staff and the chiefs of the navy, the air force and the air defense forces, all of whom were closely associated with the Mubarak era. By replacing them with his own appointees, Mr. Morsi has boldly reasserted the principle of civilian control of the military and thwarted, at least temporarily, the generals' drive to hang onto power in the post-Mubarak era. Mr. Morsi was elected in May in the country's first ever democratic presidential election, and he is acting more swiftly than many expected to consolidate his position. The timing for his move against the generals apparently was dictated by a humiliating incident earlier this month in which 16 Egyptian guards were killed by Islamic militants in the Sinai desert near the Israeli border. Mr. Morsi seized on the attack to publicly rebuke the generals for incompetence and lay the groundwork for reasserting his government's authority. By the time he cashiered the country's top generals, public opinion had swung firmly to his side. It was the latest skirmish in the running battle between the president and the military leaders who opposed his election and who have sought to undermine his authority at every turn. Just before he took office the Supreme Council of the Armed Forces dissolved the Muslim Brotherhood-dominated parliament elected earlier this year and passed a constitutional amendment stripping the president's office of most of its power over domestic and foreign policy. Mr. Morsi has now shown he is willing to push back hard against the generals' attempt to hijack the revolution. In addition to firing the most powerful members of the military council, he also announced he is nullifying the decree restricting his authority and demanding that the generals who remain negotiate a power-sharing agreement with the elected civilian government. The United States apparently was unaware beforehand that Mr. Morsi was prepared to move so forcefully and quickly. And so far, at least, there's no sign of a backlash from Egypt's remaining top generals, who reportedly have been in consultations with the government about what comes next. There's little doubt Mr. Morsi is intent on cementing the shift in power that began with his election, and despite the strong backing his candidacy received from the Islamist Muslim Brotherhood, the U.S. should continue to press the Egyptian military to avoid interfering with the country's transition to democracy. Given Egypt's history and culture it's inevitable that Islamist ideology will have an influence on the country's political evolution, but it would probably be as futile for the U.S. to try to oppose the movement as it was for the Mubarak regime during the decades when the Brotherhood was brutally suppressed. Mr. Morsi undoubtedly is aware that many Egyptians remain skeptical of the movement's commitment to the rights minorities and the rule of law, and that he must assemble a governing coalition that is broadly representative of the country's religious and ethnic groups. So far, he has done a better job at that than most expected. In principle, there's no reason Islamist ideology must be inimical to democracy, as exemplified by the case of Turkey, where a moderate Islamist party leads an elected civilian government that coexists peacefully with a military built on strong secular traditions. A similar power-sharing arrangement in Egypt not only would be something the U.S. and its allies could live with but is likely the only acceptable outcome that is realistically possible there. Democracy is an inherently messy process under the best of circumstances. So far, Mr. Morsi seems to be managing the balancing act required by Egypt's delicate political transition in a surprisingly sure-footed way.