Only 48 hours before the results of the presidential election were to be announced last June, the Supreme Constitutional Court (whose judges were all appointed by the old regime) issued a decree dissolving the parliament that was elected eight months ago. They said the rules on the eligibility of candidates had been misinterpreted, but their real aim was to get rid of a parliament where the Islamic parties had won most of the seats. Then, as the presidential votes were being counted and it was becoming clear that Morsi would win, the SCAF issued decrees that gave it the sole right to call a new election and to write the constitution under which it would be held. It also stripped the incoming President of any right to control the armed forces and, in particular, to appoint or dismiss military officers in senior jobs.
Morsi refused to recognise the legality of these decrees, but he did not openly confront the military either. He just waited for the high command to make a really embarrassing mistake - which it duly did.
Islamist fanatics had taken advantage of Egypt's revolution, which distracted everybody's attention from keeping the militants under control, to create bases in the Sinai peninsula, near the country's border with Israel. On August 5, they attacked an Egyptian border post and slaughtered 16 guards. In their own fevered imaginations, they were justly killing collaborators who were hindering true Muslims from making attacks on Israel. In the minds of most Egyptians, they had murdered 16 young men whose only crime was serving their country.
Morsi seized the opportunity to dismiss General Murad Mowafi, the head of military intelligence, for failing to forestall the atrocity.
Mowafi's post made him one of the most powerful men in the country, but nobody wanted to defend him after such an abject failure of intelligence. He went quietly - and by this action Morsi had asserted his right to remove military commanders.
The most important political skill is remembering your ultimate objectives, but biding your time until some passing event creates an opening for getting what you want. When the officer corps did not resist Mowafi's dismissal, Morsi knew that he could win a head-on confrontation with Tantawi and his cronies. They knew it too, and so they went quietly.
Egypt now has a democratically elected civilian government that exercises real control over domestic and foreign policy for the first time. What Morsi will do with that power remains to be seen, but he has won the chance to use it.
Gwynne Dyer is a London-based independent journalist whose articles are published in 45 countries.