ISIL (Islamic State in Iraq and the Levant) has had one major victory it would rather not talk about. The Sunni Islamic terrorist movement has united most Sunni and Shia groups in the Middle East. Normally militant Sunni and Shia groups see each other as their most important and dangerous enemies. Now Shia and Sunni agree that ISIL, a militant Sunni group, is their common enemy. Despite this, the normal religious animosities are still there.
Iran has always considered Sunni religious radical groups (like al Qaeda and the Moslem Brotherhood) as their main religious enemies. Now ISIL has replaced these traditional foes and groups. In fact even al Qaeda and the Moslem Brotherhood have openly turned against ISIL. While Iran does not fear ISIL succeeding in attacking Iran itself, ISIL has become a major threat to Iranian influence in Iraq (via the elected government in a country that is 60 percent Shia), Syria (where the Assad dictatorship is dominated by the Shia minority), Lebanon (where the Shia minority and the Hezbollah militia it supports are pro-Iran) and Yemen (where the Shia minority and its powerful tribal militias support are pro-Iran). The largely Sunni leadership of the Middle Eastern countries have resisted this increasing Iranian influence but despite the fact that ISIL proved to be the most effective militant force fighting the pro-Iran groups these Sunni governments side with Iran against ISIL.
This has brought about some other changes. Throughout Arabia Sunni clerics in trouble (and some in jail) for their support of al Qaeda or the Moslem Brotherhood (both of whom openly call for the overthrow of most Moslem majority governments in the Middle East) have been rehabilitated, for the moment, as allies of the government if these men will concentrate on their criticism of ISIL. In Jordan that resulted in two prominent clerics, long imprisoned for the strident support of al Qaeda, being released from jail and allowed to move freely, preach and give anti-ISIL speeches.
An irony in all this this haste to unite and battle ISIL is that in the past there was a lot of Iranian support for groups similar to ISIL (which is actually a radical branch of al Qaeda). Al Qaeda and Iran have never been close but have gotten along, in large part because they have a common enemy (the West). Al Qaeda is a radical Sunni organization that considers Shia Moslems heretics (nearly all Iranians are Shia). Iran has long provided sanctuary for al Qaeda personnel but kept all or most of them under house arrest and observation. Iran made no secret of their hatred towards this Sunni group because al Qaeda had slaughtered over 100,000 Shia since the 1990s. In that period most of al Qaeda's victims had been Moslems, most of them Shia.
Iran justified this support of a sworn (and lethal) foe of Shia Islam because of all the successful attacks al Qaeda made (or sponsored) in the West. This is something Iran wanted but was reluctant to do itself as it feared Western retaliation. Despite the sanctuary for al Qaeda leaders, Iranian official policy continued to be openly hostile to al Qaeda. For example, starting in 2008 Iranian president Mahmoud Ahmadinejad publically claimed that the September 11, 2001, attacks were a ploy by Israel or the CIA, to justify a war on Islam. Shortly after that assertion was first made public an al Qaeda leader, Ayman al Zawahri, rushed out an audio tape denouncing the Iranians for casting doubt about the fact that al Qaeda had planned and carried out those attacks. Normally the Shia avoid al Qaeda. But Iran has taken the position that “the enemy of my enemy is my friend” and provided sanctuary for al Qaeda leaders and encourages Shia to work, when possible, with Sunni terrorists like al Qaeda. The strategy is not popular with a lot of Iranians, although the Iranian government openly approved of the fact that senior al Qaeda leadership (including those outside Iran) had, since at least 2006, advised their subordinates to not kill Shia women and children. That advice has been frequently ignored but Iran has continued to work with al Qaeda when it suited Iranian interests.
One reason for this “support” of al Qaeda is that it aids in Iranian efforts to exploit and benefit from divisions within the Arab world. Currently Iraq, with its Shia majority, is willing to help Iran in many ways and this causes Sunni Arab states, especially Saudi Arabia, to accuse Iraq of betraying its Arab heritage. The Saudis also have a problem with Qatar, which backs the pro-Iran Moslem Brotherhood of Egypt. The powerful Shia Hezbollah militia in Lebanon keeps Sunni-majority Lebanon from fully supporting the Sunni rebels of Syria and their battle to remove the Shia government there. Iran has long been a major backer of Hamas in Gaza. Hamas began as a branch of the Moslem Brotherhood and is a Sunni organization that shares many traits (like hatred of Shia) with al Qaeda. Note that al Qaeda leadership officially disapproves of many ISIL actions in Iraq and Syria and is, for all practical purposes, an ally of Iran in this respect.