On December 4, less than two weeks into the standoff with Moscow over the downing of a Russian jet operating in Syria, Recep Tayyip Erdogan, the Turkish president, sent a convoy of several hundred Turkish soldiers, bolstered by tanks and armoured vehicles, deep into Iraq's territory, stirring another conflict in his country's troubled southern backyard.
The incursion embittered relations between Ankara and Baghdad and increased tensions among Iraq's embattled communities. The dispute has also threatened to draw in the rest of Iraq's neighbours, who have high stakes in the war-torn nation.
On Monday, some Turkish troops started leaving their camp in Iraq and moving north, a Turkish military source and a senior official said.
It may be too early to figure out Turkey's motives behind its military build-up in Iraq, but in many ways the confrontation appears to have been waiting to happen.
Ankara says its soldiers were sent to guard a training camp for Iraqi Sunni volunteers stationed in Bashiqa, near Mosul. The volunteers are training to take back the city from the Islamic State of Iraq and the Levant (ISIL) group. Ankara also claims that Turkish troops are in Iraq at the request of Haider al-Abadi, Iraq's prime minister.
While Abadi denies making such a request, the country's top Shia religious authority, Ayatollah Ali Sistani, instructed the government not to tolerate any infringement of Iraq's sovereignty.
Iraq's Iran-backed Shia militias, including Muqtada al-Sadr's powerful Mahdi Army, meanwhile, have vowed to put up a "decisive" fight against the Turkish soldiers.
READ MORE: Iraq's top Shia cleric voices support for protests
In that context, and as Erdogan insists that troop withdrawal is "out of the question", Turkey appears to be heading towards an escalation with Iraq.
It may be too early to figure out Turkey's motives behind its military buildup in Iraq, but in many ways, the confrontation appears to have been waiting to happen.
Ankara's operation in Iraq is still relatively limited in scale, but its military campaign marks a testing ground for Turkey's strategy in dealing with regional conflicts and for its attempt to be accepted as a key actor in the Middle East.
So, why did Ankara decide to intervene directly in Iraq, knowing that it could cause issues both with Iraq's Shia community and with Iran, which has enhanced its clout in Iraq since the toppling of Saddam Hussein in 2003?
In an interview with Al Jazeera on Friday, Erdogan shared some of his deep and bitter feelings about what he views as the reasons behind the flare up, saying Ankara's problems with Baghdad stem from the latter's "sectarian polices" against Sunnis and its alliance with Iran. The Iranian and Iraqi cooperation with Russia, Turkey's new nemesis, was another reason for the tensions.
There is much to untangle here. Relations between Iraq and Turkey have remained strained since the US-led invasion of Iraq in 2003, which empowered Iraq's Shia community and allowed Kurds to establish full autonomy in northern Iraq. Iraq's Shia community cemented relations with Iran, while some Iraqi Sunnis sought patronage from Turkey.
As the gap between the Kurdistan Regional Government (KRG) and Baghdad widened, Ankara also succeeded in co-opting Masoud Barzani, the president of Iraq's Kurdish region, whose acrimonious relationship with Baghdad has become poisonous since his Peshmerga forces seized disputed territories retaken from ISIL.
READ MORE: Anger in Baghdad over Turkish troops in Iraq
The latest display of Turkish frustration at Iran and Iraq's Shia-led government, however, is a result of Russia's build-up in Syria, which threatens Ankara's plans to establish a safe haven in northern Syria.
Ankara had hoped to use the zone to expand its influence and block an emerging autonomous Kurdish enclave on its southern border that could fall under the control of its arch enemy, the Kurdistan Workers' Party (PKK).
While its beefed-up presence in Bashiqa will allow Turkey to act aggressively to thwart the PKK's efforts to build new bases in territories retaken from ISIL, as it did in Sinjar, the Turkish strategy also aims to confront increasing Iranian influence after Iraqi forces eventually retake Mosul from ISIL.
But there are more long-term and strategic challenges that may illustrate why Turkey's response has been so determined and aggressive.
With many Iraqi Sunnis now fearful that their liberated cities will be under the control of Shia militias, Iraq is facing a severe crisis. In reinforcing its military presence in Iraq, Turkey seems to be getting out in front of the country's possible partitioning, in an effort to gain territorial advantage.
With Mosul being the last Ottoman vilayet (administrative division) to fall in World War I, the city given to Iraq under the Sykes-Picot agreement has a particular claim on the hearts and minds of many Turks.
"The sudden and dramatic moves are linked to each other. It's a stage for interested parties and local players to position and reposition themselves as events unfold," wrote Yavuz Baydar, a columnist, in the Turkish daily, Today's Zaman, on December 7.
Indeed, many Turkish politicians and commentators have been sending signals that the fate of Mosul will be Turkey's most serious challenge if Iraq collapses.
Source: Al Jazeera