Trade, Iranian influence and regional instability are drawing Turkey and Iraqi Kurdistan closer than ever before.

Turkey’s relationship with Iraq’s Kurds has not been without its problems. Not so long ago Ankara refused to deal with the Kurdistan Regional Government (KRG) and has opposed its efforts to consolidate control in disputed oil-rich areas such as Kirkuk.

Moreover, the Kurdistan Workers’ Party (PKK) has complicated the KRG’s efforts to strengthen political and economic ties with its neighbours, all of whom have historically combated Kurdish rebellions within their own territories.

Times have certainly changed. There have been landmark visits and exchanges between senior-ranking Turkish and KRG officials as well as a rapid increase in trade that has seen Turkish companies flood Kurdistan’s market and the building of a pipeline that enables the KRG to independently export its hydrocarbons to international markets.

The shift in Turkish foreign policy towards Erbil is happening despite concerns about PKK’s rebellion and Turkey’s major economic and political interests in Baghdad. It is a response to the violent instability in Iraq and the growing Iranian influence.

While Turkey has significant political and economic ties with the rest of Iraq, Ankara – like others in the Arab and Islamic world – may believe Baghdad’s Shia-ruling establishment has shifted too far into Iran’s orbit of influence and, during the course of the campaign against the Islamic State of Iraq and the Levant (ISIL) group, Tehran has further expanded its influence in the country.

In fact, Turkey may double-down on its cooperation with the KRG because of the uncertainties and challenges that may follow in the post-ISIL period, both in Iraq and Syria.

The political and administrative structures that emerge after the Islamic ISIL’s eventual defeat have as much relevance for Turkey and its geopolitical rivals as it does Iraq’s own political actors.

Forging close ties with Iraqi Kurdistan, based around mutual security, economic and strategic interests, after the Mosul operation enables Turkey to maintain a buffer against Iranian influence.

The encroachment of Shia militias into Tal Afar – some of whom include Shia Turkmen who were expelled by ISIL when it seized northern Iraq in 2014 – brings the militias closer into disputed and strategically important areas such as Sinjar, where the PKK and Massoud Barzani’s Kurdistan Democratic Party (KDP) have a significant presence.

Turkey played an important role in alleviating the humanitarian crisis that followed the first Gulf War. The ensuing western-backed no-fly zone and the creation of an autonomous Kurdish region further enabled the space for commercial ties, even if politically, and publicly, relations remained tense and constrained.

This has implications for Turkey’s security interests in the longer-run. The presence of Shia militias in the vicinity of places such as Sinjar will inflame tensions between the militias and the KRG as well as embolden the PKK, which has attempted to bring Sinjar under its own administrative control and whose fighters in Sinjar are financially supported by Baghdad.

Ankara fears that these recently emerged alliances and security structures could become stronger, especially because of the strong nexus that connects the PKK, Shia militias and Iran.

Turkey has, therefore, continued its troop presence in northern Iraq, despite threats from Baghdad and Shia militias.

Moreover, beyond the KRG, the PKK undermines Ankara’s other allies in Iraq, such as Atheel Nujayfi, the former governor of Nineveh province, whose 6,500-strong militia have been trained by Ankara.

What’s in it for the Iraqi Kurds?

Turkish influence in Iraqi Kurdistan has largely been framed as a Turkey-KDP project aimed at securing the KDP’s position as the dominant party there, to the detriment of its main rival, the Patriotic Union of Kurdistan (PUK), which enjoys closer ties to the Democratic Union Party (PYD) and the People’s Protection Units (YPG), PKK-leaning groups in Syria.

But the situation is much more complicated than that. It is commonly believed that Turkey’s strong ties with the KRG only recently emerged, when, in fact, the relationship strengthened in the 1990s.

Turkey played an important role in alleviating the humanitarian crisis that followed the first Gulf War. The ensuing western-backed no-fly zone and the creation of an autonomous Kurdish region further enabled the space for commercial ties, even if politically, and publicly, relations remained tense and constrained.

READ MORE: Money and patience grow short in Iraqi Kurdistan

Today’s political cooperation between Ankara and the KRG is an extension of these ties. Contrary to conventional wisdom, in the past both the KDP and the PUK have worked alongside Turkey against the PKK, whose Marxist-orientated vision of Kurdish nationalism runs contrary to their social-democratic and liberal outlook.

In the 1990s, the PUK founder and former president of Iraq, Jalal Talabani, attacked the PKK for “working to abort our democratic experiment and remove our parliament”.

As recently as 2009, Talabani asked the group to leave Iraqi Kurdistan. Both Barzani and Talabani were provided with Turkish passports, which allowed them to travel freely outside of Iraq and Turkey, and were even allowed to establish official representation in Ankara.

Over the past two years, the spillover from the Syria conflict has complicated Turkey’s ties to the region’s Kurds, owing to its own domestic confrontation with the PKK but also the ascendancy in Syria of the PYD and the YPG.

The Syria conflict has heightened Kurdish nationalistic sentiments and has provided the opportunity for greater Kurdish autonomy throughout the region. This has also made more difficult KRG efforts to balance domestic Kurdish sentiments with their dependency on Ankara.

Yet, Turkey is still the only reliable ally for Iraq’s Kurds. In a region that can no longer count on United States engagement, Turkey may be the least worst option for the KRG.

The Iran dimension

Iran also enjoys close ties to the Kurds and has historically provided them with a base from which to fight the former Baath regime, but it cannot offer what Turkey can.

Its nuclear ambitions, support for groups identified as terrorist organisations, support for anti-Kurdish Shia militias (who have clashed with PUK Peshmerga forces) and the anti-western rhetoric of its leadership has undermined its international standing and makes it a more unreliable, unpredictable and economically weaker ally.

Partnering with Turkey – a major military power, a NATO member and historic western ally with a resilient economy – provides the Kurdistan Region with its own “buffer” against the atomised security structures in Iraq and the rest of the region.

The state and non-state actors that threaten the Kurdistan region in the current political and security environment will think twice before challenging Turkey’s security interests in Iraq and, for now, those interests overlap with the KRG’s own.

The KRG will also benefit from increased foreign investment, technological expertise and access to the European markets. Continued interaction could also help to alleviate Turkey’s tensions with other Kurdish groups in the region and, potentially, restart the peace process with the PKK.

Ranj Alaaldin is a Visiting Fellow at Brookings Institution Doha. He specialises in Iraq and the modern history of the Middle East and holds a PhD from the London School of Economics and Political Science.

The views expressed in this article are the author’s own and do not necessarily reflect Al Jazeera’s editorial policy.