The complicated relationship between Iran and Iraqi Kurdistan has been thrown into stark relief in recent weeks. On 30 October, Adel Murad, a founding member of the Patriotic Union of Kurdistan (PUK), publicly voiced his support for the involvement of Iran, rather than Turkey or Saudi Arabia, in Iraqi affairs. The PUK is one of the largest political parties in Iraqi Kurdistan and its leader, Jalal Talabani, is the president of all Iraq, although he has been receiving treatment in Germany for a stroke he suffered in December 2012.

But on the news that Tehran had hanged two Kurdish activists on 25 October, protests were held in Iraqi Kurdistan, including outside the Iranian consulate in Erbil, opposing the Iranian government and supporting the Free Life Party of Kurdistan (PJAK), a Kurdish political movement engaged in a long-running armed struggle against Tehran. One of the two Kurds hanged, Habibollah Golparipour, was referred to by PJAK as a "senior leader." In response to the hangings, PJAK issued a statement claiming that it had taken revenge by killing ten Iranian revolutionary guards. A third Kurdish activist was subsequently hanged in Iran on 4 November.

These contradictory developments surrounding relations with Iran reflect the complex political landscape in Iraqi Kurdistan. In the aftermath of the 1990–91 Gulf war and the demilitarisation of Iraqi Kurdistan by Baghdad, a bitter civil war broke out between the left-wing PUK, under Talabani, and the more conservative Kurdistan Democratic Party (KDP), led by Massoud Barzani.

In 1998, the PUK and KDP signed a peace treaty and later joined forces in support of the 2003 US-led invasion of Iraq. Kurdish guerilla fighters, called peshmerga, fought alongside American troops in the conflict. Following the invasion, the PUK and KDP held the balance of power in Kurdistan: ruling the region in coalition, and sharing out key political offices – the presidency of Iraq is held by the PUK's Talabani, and the presidency of Iraqi Kurdistan by the KDP's Barzani.

Relations between Kurds and the Iranian government differ according to on which side of the Zagros mountains you stand. In Iran, the conflict between PJAK and Tehran has thrown salt on a long-open wound in the relations between minority Kurds and the Iranian authorities. Iranian Kurdish activists say that the promises of reform made by President Hassan Rouhani and members of his new administration seem not to apply to their region.

For Iraqi Kurds, relations with Iran must be seen through the prism of relations between Iraq as a whole and its eastern neighbour. Between 1980 and 1988, Iraq and Iran fought the longest conventional conflict of the twentieth century, and their rulers continued to espouse radically opposed visions for their countries: the political Shia Islam of Khomeini and his fellow clerics, against the Arab nationalist secularism of Saddam Hussein and the Sunni minority he led.

After 2003, with the United States, Iran's sworn enemy, embroiled in a bloody insurgency in Iraq, Tehran leveraged its popularity among the resurgent Iraqi Shia majority. Iran's influence in Iraq was illustrated by the juxtaposition of American president George W Bush's fleeting, unannounced, and heavily secured visits to US airbases in Iraq, and Iranian president Mahmoud Ahmadinejad's open-top motorcade from Baghdad airport, along a road once lined with snipers and car bombs and called by western media the "most dangerous road in Iraq" or the "Highway of Death," to a red carpet reception in Baghdad by the Iraqi president – none other than the PUK's Talabani, a fluent Farsi speaker. Sharpening the contrast, American and British officials had been banned from using the same airport road and typically travelled by helicopter to Baghdad's well-defended Green Zone.

Since 2003, following the fall of their opponents in Baghdad and with newfound autonomy and increasing security and stability, the Iraqi Kurds have gradually, but discernibly, strengthened relations with Iran. The affair did not start auspiciously. Unsettled by the participation of the peshmerga in the US-led invasion of Iraq, and worried that PJAK would find a safe harbour in Iraqi Kurdistan from which to redouble its campaign against Tehran, Iran angered the Iraqi Kurds by flouting territorial sovereignty and shelling peshmerga positions in Iraq. As recently as 2010, two weeks of Iranian air strikes and shelling sought to cripple PJAK bases in the region, and Kurdish media reported Iranian ground incursions into Iraqi Kurdistan.

Since then, Iran has grown more confident of its regional influence and, concurrently, less belligerent. In August 2010, the last US combat brigade withdrew from Iraq. After the 2010 Iraqi elections, Iran played a role in brokering the agreement in Tehran that formed a Shia-led (and broadly pro-Iranian) coalition in Baghdad, with Nouri al-Maliki, a Shia, appointed as prime minister. Those negotiations also involved the Kurds, with Talabani returning as president of Iraq, meeting a key Kurdish demand.

Political relations between Iran and Iraqi Kurdistan continued to strengthen: in August 2013, the prime minister of Iraqi Kurdistan, Nechirvan Barzani, visited Tehran for Rouhani's inauguration. An earlier visit in 2011 by the president of Iraqi Kurdistan, Massoud Barzani, to meet with Ahmadinejad, his then-counterpart, was heralded by energy industry analyst John Daly as "proof of the changing regional dynamics," in which Iran was successfully subverting America's influence over Iraqi affairs.

And instead of throwing its weight about militarily, Iranian influence on daily life in Iraqi Kurdistan is now softer, but no less persuasive. Trade between Iran and Iraqi Kurdistan is making far greater inroads than military operations ever did. Last year saw a visit to Iraqi Kurdistan by the Iranian vice president for international affairs and a delegation of more than 100 Iranian companies as part of the Iranian-Kurdistan Region Economic Forum.

This July, the Iranian first vice president welcomed the Iraqi Kurdistan minister of housing and development, amid announcements that a new bilateral trade agreement had been signed and that trade between Iran and Iraqi Kurdistan was expected to surpass $4 billion in 2013. In 2000, before the war, the officially reported volume of trade was only $100 million.

But Iran still has some way to go to catch up with another regional heavyweight, Turkey. The historical relationship between Turkey and Iraqi Kurdistan is similar to Iran's. Like Tehran, there is deep-rooted hostility between Ankara and its Kurdish citizens. Like Iran and PJAK, Ankara has been embroiled in a long-running conflict inside Turkey with the Kurdistan Workers' Party (PKK), a left-wing Kurdish movement whose leader, Abdullah Öcalan, is currently in prison. Like Iran, Turkey shelled, bombed, and even sent ground troops against PKK positions inside Iraqi Kurdistan in the aftermath of the US-led invasion.

Earlier this year, however, the PKK signed a ceasefire with Ankara and the two sides are engaged in peace negotiations. And Turkey has moved even more vigorously than Iran in investing in Iraqi Kurdistan, throwing its weight into politically important, big-ticket infrastructure projects. Half of all foreign companies registered in Iraqi Kurdistan are Turkish, and trade between Ankara and Erbil is $8 billion, double the Iranian figure. Oil-rich Iraqi Kurdistan has attracted investment from the major international energy companies – and the largest oil producer in the region is the Turkish company Genel Energy, listed in London and run by former BP chief Tony Hayward.

Erbil is finalising the connection of its oil supplies to the Kirkuk-Ceyhan pipeline, which carries oil from Iraq proper to energy-hungry Turkey and the port of Ceyhan. At the end of October, Erbil announced its plans for a second pipeline that will directly link Iraqi Kurdistan to Turkey, free from any interference from Baghdad. Even the ancient round citadel in Erbil bears the hoardings of 77 Construction group, a major Turkish-Iraqi joint venture.

Although currently smaller than the Turkish connection, the economic relationship between Iran and Iraqi Kurdistan is blossoming, and it is by no means a one-way street. Over the years, there have been well-documented allegations of sanctions-busting oil smuggling from Iraqi Kurdistan to Iran, in defiance of Baghdad and the international community.

These allegations were denied in July this year by Ashti Hawrami, the Iraqi Kurdistan oil minister, although in August Reuters claimed that as many as 30,000 barrels per day of crude oil were being smuggled from Iraqi Kurdistan to Iran's Bandar Imam Khomeini terminal on the Persian Gulf. A rise in smuggling across the Kurdistan-Iran border was recently reported, along with an increase in the deaths of kulbars, or smugglers, totalling around 100 over the past two years. Similar allegations have been made in respect of arms trafficking and money laundering.

The relationship between Iran and Iraqi Kurdistan is thus more evenly balanced than might be expected, even surprisingly so. After all, Iran is a powerful country of 80 million people that operates a globally infamous nuclear programme, while Iraqi Kurdistan is but a region of Iran's smaller, western neighbour. But there are opportunities on both sides. Trade is blossoming, and Iranian cultural influence in the area is centuries old. Iran has fostered good relations with the KDP and the PUK, both of which are increasingly striving to hedge Iraqi Kurdistan's economic growth with inbound investment from a basket of neighbouring countries. Politically, Iran has achieved a government in Baghdad with ties to Tehran through its negotiations with the Iraqi Kurds, in return for which the Kurds have held onto the presidency of Iraq.

In all these areas, Iran has dealt with Iraqi Kurdistan as an equal. But the recent hangings in Iran reminded Iraqi Kurds of something they seemed to have forgotten: when it comes to the Kurds inside Iran, especially PJAK, no amount of friendship with Iraqi Kurdistan will temper Tehran's fury.