Turkey is seeking to protect its economic and political interests in northern Iraq while fighting against PKK and ISIL.

Many commentators seem perplexed about Turkey’s willingness to be a part of the ongoing Mosul operation.

There are a number of concrete interests that drive Turkey’s approach: limiting the area of operations of the Kurdistan Workers’ Party (PKK) and its Syrian offshoot the YPG; supporting the Kurdish Peshmerga forces against the Islamic State of Iraq and the Levant (ISIL); protecting Turkmens; preventing and managing potential refugee outflows; and helping Mosul remain stable in the post-ISIL period.

The row between Ankara and Baghdad appears to emanate from Baghdad’s desire to reduce the Turkish, Sunni and Kurdish influence in Mosul when ISIL is pushed out of the city.

Turkish forces in northern Iraq

The Turkish military presence in northern Iraq, particularly in Bashiqa, is directly connected to the rapid rise of ISIL in the summer of 2014. Most observers were surprised by how sudden and complete the fall of Mosul to ISIL was, and were shocked by the group’s rapid capture of large swaths of land in Iraq and Syria. When the city fell into the hands of ISIL, there were serious concerns on the part of the international community that the militants could even march to Baghdad.

Turkey had long cultivated strong economic and political ties with the Kurdish Regional Government (KRG) as well as various Sunni and Turkmen groups in Iraq, which made it a major stakeholder especially in northern Iraq. Extensive Turkish investments in the region were directly threatened by the rise of ISIL.

In June 2014, when it captured Mosul and declared its “caliphate”, ISIL abducted 49 Turkish diplomatic personnel in the city, including the Turkish consul. Months-long rescue efforts prevented a direct Turkish military action against ISIL until the hostages were finally freed in September 2014.

Just as it released the Turkish hostages, ISIL surrounded the small city of Kobane on the Syrian-Turkish border, driving new waves of refugees into Turkey. In an unprecedented act of military coordination, Turkey allowed Kurdish Peshmerga forces to travel through its territory to prevent the fall of the city to ISIL. This operation laid the groundwork for deeper military cooperation with the KRG in Iraq.

Turkey has long maintained its commitment to Iraq's integrity and unity, as the potential break-up of the country would only deepen the conflicts and worsen the humanitarian outlook for the region. However, given the autonomy the KRG enjoys and the collapse of the political compact in the country since the US invasion, for some observers, Iraq's integrity is a bit of a fiction by now.

At the time, Turkey was pursuing a reconciliation process with the PKK, an effort supported by KRG President Massoud Barzani. Turkey had long been suspicious of the PKK-linked Democratic Union Party’s (PYD) ambitions to create de facto autonomous zones in northern Syria and opposed US military aid for the YPG militants.

Despite Turkish objections, the US continued to support the YPG and turned a blind eye to the creation of de facto autonomous cantons in northern Syria. This has remained a sore point in US-Turkey relations, particularly after the reconciliation process collapsed and fighting resumed between Turkey and the PKK in July 2015.

Two important interests

Turkey’s recent Operation Euphrates Shield in Syria aims to drive ISIL away from its borders and concurrently thwart PYD’s ambitions to connect its cantons. If the PYD were to do so, it would effectively create a PKK statelet along the Turkish border.

Therefore, Turkey’s insistence on its military presence in Mosul is guided by a similar set of interests and military posture as in northern Syria.

While the PKK does not command the kind of resources and legitimacy that the KRG enjoys, their presence and efforts to gain legitimacy as a bulwark against ISIL is a major concern for Turkey. Thus, counterbalancing and limiting PKK activities while supporting the KRG are two important Turkish interests in Iraq.

OPINION: The day after the battle for Mosul

The Bashiqa base was established as a military training camp in March 2015 after the fall of Mosul and Turkey’s decision to support KRG against ISIL. Turkish Defence Minister Ismet Yilmaz visited Baghdad and promised support to the Iraqi army and Peshmerga forces in the form of “equipment and training” to retake Mosul from ISIL.

Turkey has long maintained that the Bashiqa base was established with the knowledge and approval of the Iraqi government.

In fact, the Iraqi Defence Minister Khaled al-Obaidi is seen in a video when visiting the military camp. This was surely at a time when the Iraqi government felt most threatened by further ISIL expansion and sought whatever help it could get.

Since then, the international anti-ISIL coalition – of which Turkey is a member – has appeared to make some headway in pushing back ISIL. As a direct result, Baghdad has become more comfortable in its posture and reverted back to targeting the Turkish presence in northern Iraq.

Baghdad’s changing stance towards Turkey

In December 2015, the Iraqi government gave Turkey an ultimatum to pull its military forces from Bashiqa and threatened to go to the United Nations Security Council. Turkey announced that no additional troops would be sent but it refused to pull its forces, a decision welcomed by the KRG. Ankara reassured Baghdad that Turkish troops were there to train local Peshmerga forces against ISIL and it respected Iraq’s territorial integrity.

When Baghdad’s deadline passed without Turkish withdrawal, Iraqi Prime Minister Haider al-Abadi called on NATO to “use its authority to urge Turkey to withdraw immediately from Iraqi territory.” At the time, Abadi’s stance against Turkey was probably a reflection of Russian pressure on Iraq following Turkey’s downing of a Russian jet in November 2015.

Most recently in October 2016, the Iraqi prime minister again threatened to go to the UN over the presence of Turkish soldiers in Bashiqa, which he said constitutes a violation of Iraqi national sovereignty.

His words drew a sharp rebuke from Turkish President Recep Tayyip Erdogan who reiterated Turkey’s readiness to actively fight in the impending coalition operation to liberate Mosul. Turkey vowed to stay to support the fight against ISIL largely because of its strong relations with Sunni Arab and Turkmen groups as well as the KRG.

OPINION: The battle for Mosul – The beginning of the end

Under Nouri al-Maliki, the previous Baghdad government had pursued sectarian policies. These policies and numerous massacres against Sunnis led to the collapse of Sunni-Shia relations and a dramatic rise in sectarian tensions in the country. Turkey has been wary of a repeat of the same scenario in the ongoing Mosul operation as well as in the post-ISIL Mosul.

Turkey has long maintained its commitment to Iraq’s integrity and unity, as the potential break-up of the country would only deepen the conflicts and worsen the humanitarian outlook for the region.

However, given the autonomy the KRG enjoys and the collapse of the political compact in the country since the US invasion, for some observers, Iraq’s integrity is a bit of a fiction by now.

Turkey is seeking to protect its economic and political interests vis-a-vis the KRG government while fighting against PKK and ISIL, both of which continue to attack Turkey.

Under normal circumstances, the Turkish presence in Iraq would probably have violated the country’s sovereignty. Currently though, the dysfunction and collapse of the Iraqi political system appear to have rendered that point moot.

Kadir Ustun is the Executive Director of the SETA Foundation in Washington DC.

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