Although the Iranian debate about what to do in Iraq has not been as loud as the one in the United States, it has been equally intense. That should come as no surprise. For Iran, a civil war in neighboring Iraq, or a partitioning of that country, is less an occasion for political score-settling (as in Washington in recent days) than a threat to national security.

Iranian policymakers understand that, and their recent public statements make it possible to discern the basic outlines of Iran’s strategy. On the one hand, Tehran will shore up the Shia-dominated government of Iraqi Prime Minister Nouri al-Maliki as it organizes Shia-dominated military forces and informal militias to combat the Sunni insurgents that have gained control of northwestern Iraq. On the other hand, Tehran will attempt to frame the conflict in Iraq in nonsectarian terms, presenting it, instead, as a war against terrorism. That rhetoric, Tehran hopes, will convince the West, particularly the United States, to send political and military support.

There are obvious tensions between the rhetorical and operational aspects of this strategy, and Iranian policymakers may be less capable of finessing those tensions than they would like to think.

Since the end of the war between Iraq and Iran in 1988 and the U.S. invasion of Iraq in 2003, Iran’s priority has been to ensure that Iraq would never again invade it. To that end, it has focused on establishing a Shia-dominated government in Baghdad that is friendly to Tehran. It has also cultivated Shia political networks in Iraq and created a number of powerful Shia militias. As a result, Iraq has become a clear Iranian ally and a major trading partner. This has tipped the strategic balance of power in the region in favor of Iran and against its rival, Saudi Arabia.

Iran is not likely to undo all that progress by abandoning its ally; solidarity is a mainstay of the political rhetoric of Iran’s supreme leader, Ayatollah Ali Khamenei. When the city of Mosul fell to the Sunni insurgent group Islamic State of Iraq and al-Sham (ISIS), Tehran's immediate instinct was to quickly offer military help to Maliki, whom it has long backed. But this is not simply a matter of personal loyalty. Iran's strategic priority in Iraq is ensuring that Iraq’s government remains dominated by Shia, with or without Maliki at the helm.

In the days since Iranian President Hassan Rouhani announced that he would be sending help to Maliki, if asked by Iraq, Iran's Islamic Revolutionary Guards Corps (IRGC) has taken the lead in coordinating the military operations of Iraqi security forces. (There have already been reports that Qassim Suleimani, commander of the Quds division of IRGC, has been dispatched to Baghdad to assist Maliki.) IRGC's rather successful involvement in Syria's civil war -- where it trained and fought alongside Syrian government forces -- has given it practice in combating ISIS and other Sunni extremist groups. But IRGC also knows the Iraqi terrain very well. During the U.S. occupation of Iraq, it trained thousands of Iraqi fighters and gained an intimate familiarity with the fault lines of the country's politics.

Iran can also help mobilize the Shia militias in Iraq that have mostly been dormant in recent years. It will surely try to regroup and re-arm the Iranian-trained Badr Brigade (although many of its members have since joined the Iranian national security forces). It will probably also take the more controversial step of encouraging the Shia militant cleric Muqtada al-Sadr's powerful Mahdi Army to join the fight. During the U.S. occupation of Iraq, Sadr famously ordered his militia to fight U.S. troops, and he gained a reputation for recklessness as a political and military leader. Tehran has repeatedly intervened on Maliki's behalf to subdue the erratic cleric's militia. But Tehran now seems to have changed its mind about Sadr, at least for the duration of the current crisis. After a recent trip to Iran, Sadr declared that he would instruct his militia to defend Shia shrines against ISIS.

Finally, Iran may turn to smaller Shia insurgent groups, including Asaib Ahl al-Haq, an offshoot of the Mahdi Army, and Kataib Hezbollah. Iran reportedly created and trained both. Now they are among the militias that IRGC expects to respond to its commands. (Both of those groups have also been fighting in the Syrian civil war and thus are already familiar with ISIS.)

Iran believes that the Sunni insurgency can only be defeated if Iraq's fractious Shia militias agree to cooperate. Fortunately, Iranian-born Grand Ayatollah Ali Sistani, the most popular Shia religious leader in Iraq and perhaps the world, has encouraged them to do just that. After the fall of Mosul to ISIS, Sistani issued a fatwa urging all Shia to unify and join the government security forces for a fight against ISIS. This was an unprecedented move: even at the peak of the sectarian civil war during the U.S. occupation, Sistani had refused to issue a fatwa to urge the faithful to take arms. Sistani's intervention proved an important turning point; ISIS seemed to be on the verge of reaching Baghdad, but the fatwa seemed to stall him. It produced a steady number of volunteers for the Iraqi national security services and Shia militias, and put pressure on Maliki’s political opponents in Baghdad to back the embattled prime minister.

Although Tehran’s goal is to keep Iraq’s Shia government in power -- and its opponents in ISIS openly want to establish a Sunni-only state -- Iran is very unlikely to admit publicly that its strategy is overtly sectarian. Iranian officials are exceptionally careful not to identify the ISIS as a Sunni organization, or even as an indigenous Iraqi group, but rather as a takfiri, or infidel, group that relies on the support of outside countries. Khamenei recently warned that "some regional countries unfortunately do not take heed of the danger of [the] takfiri groups, which will threaten them in future … eventually these countries will be forced to eradicate these extremists, with a high price." Although Khamenei did not identify which countries he had in mind, the Iranian media consistently point to Saudi Arabia as the main source of funding for ISIS and other Sunni jihadists. Rouhani has emphasized that Iran has “no option but to confront terrorism in Iraq.”

Framing its intervention as an antiterrorist bid allows Iran to publicly and privately pressure the United States and the West to back (or at least not oppose) its efforts. Some Iranian policymakers believe that there is good reason to collaborate with the United States in fighting ISIS. Just as they worked together to overthrow the Taliban in Afghanistan in 2001, Iranians want to work with Washington to prevent the partition of Iraq. They appreciate that, although the United States and Iran don’t necessarily need to cooperate militarily in Iraq, political cooperation between Washington and Tehran will be indispensible for restoring stability in Iraq.

But Iran seems more reluctant to admit that the United States has a somewhat different vision of how peace can sustainably be restored in Iraq. Iraq will not remain stable so long as Shia exclusively dominate the Iraqi central government. ISIS’ rapid advances were only possible because the population of Sunni-majority areas of Iraq felt entirely alienated from the political process in Baghdad and believed that ISIS offered them a better opportunity to govern their own affairs. In that sense, there is simply no military solution to the lingering crisis in Iraq. Iran, as the most powerful regional player in Iraq, would be wise to pressure Maliki to make meaningful concessions to the Sunni population and involve them in the central government’s decision-making in order to make them feel that they are an integral part of a new Iraq. That would allow Iran to not only defeat ISIS but to sustain its favorable position in Iraq and to lay the foundation for a more cooperative relationship with the United States in the region. Otherwise, Iraq will remain a perpetual security threat on Iran’s western border.