Police control the scene around the shrine of late Iranian revolutionary founder Ayatollah Khomeini, just outside Tehran, after an attack on Wednesday. (Ebrahim Noroozi/AP)

This month, the Islamic State successfully carried out its first attack on Iranian soil, resulting in 17 dead and some 50 injured. Iran is a top target for the Islamic State — and has been since the group rose to prominence in 2014. But Iranian security forces had effectively thwarted the threat through an extensive counterterror program. Iran took pride in keeping the fight against the Islamist militants outside its territory. Until now.

Threats grow from sectarian roots

The Islamic State views Shiite Muslims as apostates. It portrays Iran as a Shiite power threatening the “real” Muslim community — the Sunnis. Because of this — and the threat the group poses to Iran’s interests in the region — Tehran views the Islamic State as a national security threat. As a result, it placed “no limits” on resources to combat it both inside and outside its borders

To tackle the Islamic State, Iran developed an extensive counterterror program. Iran’s goal is to undermine the Islamic State’s spread, ideology and vision, while working to prevent attacks on Iranian soil or against Iranian citizens. The Iranian approach to countering the Islamic State is more hands-on than that of the U.S.-led coalition, because by virtue of proximity, Tehran feels the threat more acutely.

Iran draws on its relatively strong and stable state, with its notoriously effective security services to implement its counterterror measures. Tehran targets the Islamic State directly to disrupt its operations. It sends advisers, military personnel and supplies and money to tackle the group in Syria and Iraq to avoid conflict within its own borders. It also conducts a messaging campaign to tackle the group’s ideology by highlighting unity among Muslims and signals its commitment to the fight by showcasing the Islamic Revolutionary Guard Corps’ (IRGC) presence outside its borders.

To lessen the sectarian aspect of the conflict — after all, Iran wants to lead all Muslims, not just the Shiite minority — Tehran engages with various political and religious groups fighting the Islamic State, including the Iraqi government and Army, Kurdish fighters and Sunni groups.

Inside Iran

Domestically, Iran undertook a number of anti-radicalization measures, in coordination with the minority Sunni community to tackle the Islamic State’s effort to recruit inside Iran. While somewhat successful to begin with, in 2016, Iranian official admitted that the Islamic State had tapped into Iran’s Sunni minority for recruits.

It carried out extensive intelligence operations to thwart planned attacks. In July, for example, Iran’s Intelligence Ministry successfully defused an Islamic State plan to conduct a large-scale terrorist attack across Tehran, involving 50 targets using more than 200 pounds of explosives.

But given that Iran was a major target, it was unlikely to escape attacks completely.

Islamic State fighters increase focus on Iran

By summer 2016, the Islamic State reportedly lost almost 50 percent of its territorial gains in Iraq. As the fight continues to make progress, the group is lashing out. In the past few months, it upped its anti-Iran propaganda and outlined its vision to conquer Iran to return it to Sunni rule. Iranian officials were quick to dismiss the threats, saying the Islamic State could not create insecurity in Iran. The group also published four issues of its online publication Rumiyah, in Persian.

After a number of failed attacks, the Islamic State succeeded in simultaneously targeting Iran’s parliament and the shrine to Iran’s religious leader Ayatollah Ruhollah Khomeini; symbols of democracy and revolution in Iran. The attack will significantly boost the Islamic State morale, at a time where it is facing a losing battle in Iraq and retreating in Syria.

What’s next for Iran?

The attack will spark calls for revenge and a display of strength by the government from conservative quarters. Hard-liners, recently defeated in a presidential election, will point to the attack as proof that President Hassan Rouhani’s focus on moderation doesn’t work.

The attack will increase public support for the IRGC, who are viewed as the country’s protectors. They were first to respond to the attacks and dealt with the terrorists swiftly, earning themselves the praise of both those caught in the attack and the government. The attack will also spark calls for an expansion of efforts to fight the Islamic State in Iraq and Syria, despite the lack of popularity of Iran’s efforts in Syria.

And yet if the politics in Iran around regional policy will change as a result of the attack, it’s unlikely that the actual policy will. Iran is already heavily invested in both countries. It doesn’t have unlimited resources, and it is already losing soldiers and political capital in both countries.

Most notably, the attackers were Iranians. But the Iranian population will be looking for someone to blame. Saudi Arabia’s deputy crown prince gave them the opportunity: Last month, he said they would “take the battle to Iran.” Some Iranians, encouraged by the IRGC, drew links between his statements and the attack itself. The already unpopular idea of dialogue with Gulf Arab neighbors will become significantly less popular, and more difficult. And this, at a time when regional coordination is necessary to tackle the threat of terrorism.

Iran’s extensive and multilayered counterterrorism program was successful in preventing an attack within Iran’s borders and against Iranian civilians. Until last week’s attack. It is unsurprising that an Islamic State-sponsored attack slipped through the cracks, given Iran’s significance as a target for the group. The attack, a boon for the Islamic State’s morale, will make Rouhani’s goal of engagement with Gulf Arab neighbors more difficult, but — given its limited resources — will not see Tehran significantly increasing its efforts in neighboring Iraq and Syria.

Dina Esfandiary is a Centre for Science and Security Studies (CSSS) fellow in the War Studies Department at King’s College London and an adjunct fellow (nonresident) in the Middle East Program at the Center for Strategic and International Studies (CSIS).