On balance, the recent toppling of President Mohammed Morsi by the Egyptian army is likely to be to Iran's advantage, at least in the short to medium term.
Iran is likely to feel the biggest gain from this development in Syria.
Morsi was no simple foe of the Iranian regime's ally Bashar al-Assad — he was the leader of the world's most populous Arab country. His status as a democratically elected official, plus his closeness to the Muslim Brotherhood, one of the world's most powerful Sunni political organizations, made him an even more powerful enemy. Morsi's democratic and Sunni credentials gave him enviable credibility, which Tehran and Damascus found very difficult to match.
When Morsi spoke, people listened both outside and inside Iran, something that worried the Iranian regime. This is one reason why, when he spoke against Assad at Tehran's Non-Aligned Movement conference in August 2012, every one of his mentions of “Syria” was swapped with "Bahrain" by Iranian translators.
Had the same scenario happened during the era of Mubarak, an unelected secular leader with close ties to the West and Israel, it would have been unlikely that his position against Assad would have carried as much weight.
Now that Morsi has been toppled by the Egyptian army, which has close ties to the United States, whoever replaces him is unlikely to have the same credibility in confronting Syria in the Islamic world, especially in the Middle East. This will be to Iran's advantage.
It would also be to Iran's advantage if a civil war erupted in Egypt, or at the very least an internal terrorism campaign launched by the Brotherhood or other Islamic militants. Either development would bog the Egyptian government down in domestic problems. This would translate into less time and resources for political intervention in Syria. It could also mean that Islamic militants may use the ensuing chaos as an opportunity to launch attacks against Israel from the Sinai.
2. Gaza and Hamas
Iran is also likely to feel a gain from Morsi's fall in Gaza.
In fact, this is where both Ayatollah Khamenei and Assad received the first taste of Morsi's power when Hamas left them for Egypt. Morsi did not do this alone. The actions of Damascus and Tehran helped push Hamas toward him. Such actions included Assad indiscriminately bombarding Palestinian refugee camps in Syria. Furthermore, despite years of claiming that it supports the Palestinian people, not only did the Iranian regime not condemn the indiscriminate killing of Palestinians by Assad's forces, it continued to provide support to him. That Morsi was the democratically elected leader of a neighboring Arab country with ties to the Brotherhood (an organization close to Hamas) helped Morsi's efforts to pull Hamas toward him.
Now that Morsi has been toppled, Hamas is going to feel very isolated. Such isolation could make it easier for Iran to get close to Hamas again. Hamas' new isolation could mean that unlike before, this time it may have to ignore Assad's continued killings in Syria. Desperate times could call for desperate measures and Iran may be the only one willing to help Hamas, something that Hamas' leaders may find hard to resist, as their old ally Morsi is no longer in charge in Cairo.
The fall of Morsi has meant that the Qatari regime has lost an important ally. This will be good news for Iran as the Iranian government has been worried about Qatar's increasing influence in the region, which Tehran was uneasy with when it came to Assad. Both Tehran and Doha had been at loggerheads over this issue.
4. Obama and US credibility
What is likely to be the icing on the cake for Iran is the absence of an outright condemnation from US President Barack Obama against the recent coup in Egypt, as this is likely to hurt his pro-democracy credentials in the region. What's even more embarrassing for Obama is likely to be that his Republican rivals, such as Sen. John McCain, were far quicker and more vocal in their calls to temporarily suspend aid to the Egyptian armed forces due to their assistance in the overthrow of a democratically elected government.
In the long run, what can turn the situation against Iran is if fair elections are held again in Egypt, in which all parties, including the Brotherhood, are allowed to participate. The return of democratic legitimacy to Egypt would be bad news to Iran, as this is likely to make Cairo a powerful rival — again. This is especially true if an Islamic movement wins, as Egypt would win again where the Islamic Republic has failed in the last 34 years — presenting itself as a genuinely elected democratic Islamic government.
For now, and probably much to the Iranian government's advantage, the chances of the realization of such a scenario in Cairo seem remote.