There are over 13 million Kurds on both sides of the Iran-Iraq border. Whether under the shah or the Islamic Republic, Iran has been the only country that has had an overall cordial relationship with Iraqi Kurds, be it secular, Marxist or Islamic parties. The shah and the ayatollahs both adopted the strategy of engaging enemies outside Iran’s borders. In Iraq, this has entailed weakening successive Iraqi regimes by partly using the Kurds as a proxy force . Indeed, repression from Baghdad combined with Tehran’s assistance to the Kurds greatly contributed to Iraq almost always being at war with a quarter of its population. For instance, the Kirkuk oilfields were attacked by peshmerga, both during the shah’s reign in the late 1960s and the ayatollahs in the 1980s . Nonetheless, ironically, while Iran has been wary of Kurdish aspirations for independence, its continuous support for the peshmerga in past decades has ensured that the desire for independence continued burning amongst Kurdish fighters — and their leadership.

The political parties in Iraqi Kurdistan have all made it clear that their ultimate aim is an independent Kurdistan, but they differ on the approach, meaning that the issue of independence is a matter of “when” rather than “if.” The Iranians are perhaps more aware of this than any other actor.

While Turkey and Iraq's opposition is understandable to an extent, Iran's long involvement as well as cultural and historical ties with Iraqi Kurds raises serious questions about the motives for its opposition to the upcoming referendum.

"The Islamic Republic of Iran opposes some murmurs about holding a referendum in order to separate one part of Iraq," said Iranian Supreme Leader Ayatollah Ali Khamenei in a meeting with visiting Iraqi Prime Minister Haider al-Abadi in June, adding that Iraq "should stay unified."

As Iraqi Kurds try to iron out internal differences ahead of their referendum on independence in September, Turkey , Iraq and Iran have all announced their opposition, questioning the timing and fearing the implications of such a move at a time when regional rivalries are at their peak.

However, Iran’s assistance to Iraqi Kurds, partly in order to use them against its own rebellious Kurds, has also caused immeasurable damage to its own stability and security. When Iran fought a bloody battle against Iranian Kurds in the 1980s, it had to devote huge resources and enormous manpower to contain them. Most Islamic Revolutionary Guard Corps (IRGC) top brass, including top commander Mohammad Ali Jafari and Quds Force commander Qasem Soleimani, are veterans of the war in Iranian Kurdistan. Other senior IRGC personnel who have been killed in Syria and Iraq in recent years started their careers in the mountains of Iranian Kurdistan. On the other side of the coin, representatives of the IRGC and the Iranian Ministry of Intelligence have been present in Iraqi Kurdistan since the mid-1980s, offering Tehran close knowledge of the Kurdish leadership and the Kurdish region inside out.

This knowledge has led Iranian officials to retain great pragmatism, perhaps also guided by the experiences of its neighbor Turkey, which has for decades been mired in armed conflict with the Kurdistan Workers Party and more recently the latter’s affiliates in northern Syria. The impact of this pragmatism has been compounded by consistent acts of solidarity, although oftentimes motivated by Iran’s own interests.

In the summer of 1988, under the regime of Saddam Hussein, Iraqi Kurdistan was devastated by chemical weapons and the murder of 182,000 civilians. While the Persian Gulf states funded Saddam, and the West, including the United States, UK and France, armed his regime to the teeth, Iran welcomed thousands of fleeing Kurds into its territory. During the 1991 uprising in the aftermath of the Gulf War, Iran again opened its borders and allowed Iraqi Kurds to find shelter on its soil, while Turkey closed its borders. In August 2014, when the Islamic State (IS) invaded Iraqi Kurdistan, the Iranians were again the first to assist the Kurds. "I think all Kurds should always be grateful to the Iranians, even though they had their own interests too," a peshmerga captain who dealt with the Iranians at the time near Erbil told Al-Monitor. In this vein, apart from security considerations, it should be noted that Iran’s annual trade with Iraqi Kurdistan is almost $8 billion.

Thus, given Iran’s relationship with its own Kurdish community as well as its long history of assistance to Iraqi Kurds and their political parties, it is in a relatively strong position vis-a-vis Ankara and Baghdad.

With the crumbling of IS, the future looks even bleaker as new rivalries spring up. Turkey is at war with its Kurdish community and vehemently opposes the Kurdish administration in northern Syria. Syria remains mired in chaos, with the central government unable to control a large chunk of its territory — perhaps permanently. Meanwhile, Iran is relatively stable and has deployed thousands of troops to Syria and Iraq to fight jihadists and shore up the defenses of its allies in Damascus and Baghdad.

Iranian officials have repeatedly stated that if they do not fight jihadists in Aleppo and Anbar, they would have to fight them on their own soil. Given the Kurdish background of the perpetrators of the terrorist attacks in Tehran on June 7, it appears that the one area where the security of Iran could be most threatened is the Kurdish region.

Thus, given the complex and dangerous regional landscape, as well as Iran’s domestic security situation, the referendum on an independent Kurdistan places the Islamic Republic at a crossroads. If the Kurds manage to iron out their internal differences and hold the vote and then declare independence, Iran will have to think hard before it makes its final decision about its posture toward a Kurdish state.

Tehran could support an independent Kurdistan that boosts economic and security cooperation while receiving guarantees that such an entity will not become a source of instability on its borders. Iran could also benefit from providing an alternative route for Kurdish oil to find its way to international markets.

Conversely, the Islamic Republic could oppose statehood for Iraqi Kurds by closing its airspace, imposing an economic blockade and using its Shiite proxies in Iraq to cause nuisances, but that could potentially open the gates to a Kurdish revolt on both sides of the border and invite possible foreign interference to its immediate west. Given that Saudi Arabia, the enemy of Iran, has given positive signals toward Iraqi Kurds — and Riyadh’s alleged support for Iranian Kurdish militants based in Iraqi Kurdistan — a continued autonomous Kurdistan region supported by the Saudis could become a challenge perhaps greater than the threats posed by an independent Kurdish state.