According to a senior security source, the breaking point between Morsi and the generals came in February, when the outgoing Iranian president, Mahmoud Ahmadinejad, visited Cairo.

It's an interesting theory. Iran certainly began pushing the security boundaries of Egypt after Morsi's victory. There were Iranian warships and subs in the Suez Canal. But a lot of that fell apart as the Syrian Civil War intensified with Iran on one side and the Muslim Brotherhood on the other.

Despite Morsi’s surprise, the warning signs had been flashing for months. The generals had been growing restive over what they perceived as the president’s incompetence and apparent intention to pursue hardline Islamist policies — including an alignment with Iran.

According to a senior security source, the breaking point between Morsi and the generals came in February, when the outgoing Iranian president, Mahmoud Ahmadinejad, visited Cairo.

At the manicured country clubs, where generals and business tycoons routinely rub shoulders, there was alarm. Was Egypt, with its largely Sunni Muslim population and traditionally secular policies, about to ally itself with the revolutionary Shi’ites in Tehran?

Was the army, with its close links to the American military and subsidies of $1.3bn (£870m) a year from the US taxpayer, about to ally itself to Washington’s sworn enemy?

Sisi, appointed army commander by Morsi last August, was furious — particularly when rumours swept Cairo that the president was about to sack him. Sisi’s suspicions of Morsi grew when Ahmadinejad announced that he had offered to defend Egypt in the event of an attack.

According to the Egyptian weekly Al-Usbua, “Sisi told the president the army objected to his remarks, which were an insult to the military and questioned its strength and its ability to face threats to the security of the country.”

The trouble with this version of events is that Ahmadinejad's visit was ugly and troubled at best. He had shoes thrown at him and was told off in Al Azhar. Morsi did greet Ahmadinejad, but it meant very little. It probably irritated the military, but it irritated a lot of the Islamists even more.

All of these issues came to surface during Ahmadinejad's short visit to Cairo, some of it an embarrassingly public way. He was greeted only briefly by Morsi and the two held a short meeting at the airport, but there are no scheduled bilateral meetings scheduled during the summit.

Ahmadinejad also paid a visit to Al Azhar, the academic center of the Sunni Islamic world, where he met the most senior scholars of Sunni Islam to discuss Syria, Bahrain and other issues.

At an awkward press conference, the deputy head of Al Azhar, Sheikh Hassan el Shifai, was highlighting points of agreement between them when Ahmadinejad abruptly interrupted to say, “we did not agree, we did not agree.”

Afterward, Ahmadinejad went to pray at one of Cairo's most sacred mosques, Al Hussien. As he left, group of Salafist Sunni Muslims protested his visit and one threw a shoe at him.

Iran, in its first official reaction to the toppling of Egypt’s democratically elected president by the military, called the move “improper.”

A Sunday report by official IRNA news agency quoted foreign ministry spokesman Abbas Araghchi also saying that supporters of Mohammed Morsi should not give up in their quest to reinstate him. He also said the presidency should not be decided by “the streets.”

“Islamists and revolutionaries should not be frustrated,” said Araghchi. “Arab Spring can be followed by warm summer and cold winter,” too.