SOCHI - Russia and Turkey agreed on Tuesday to ensure Kurdish forces withdraw from areas close to Syria's border with Turkey and to launch joint patrols, in a deal hailed as "historic" by President Recep Tayyip Erdogan.
After marathon talks in Russia's southern city of Sochi, Erdogan and his Russian counterpart Vladimir Putin announced the deal just hours ahead of a deadline for Turkey to restart its assault on Syrian Kurdish forces.
The agreement cements Russia and Turkey's roles as the main foreign players in Syria, after US President Donald Trump announced the withdrawal of American forces from the country's north earlier this month.
That announcement cleared the way for Turkey to launch a cross-border offensive on October 9 against the Kurdish YPG militia, viewed by Ankara as "terrorists" linked to the outlawed Kurdistan Workers' Party (PKK).
Turkey has seized control of a "safe zone" inside Syria about 120 kilometres long (75 miles) and 32 kilometres (20 miles) deep.
Tuesday's agreement with Moscow will see it preserve that zone between the towns of Tal Abyad and Ras al-Ain, giving Ankara a crucial presence inside the country.
From noon (0900 GMT) on Wednesday, Russian military police and Syrian border guards will "facilitate the removal" of Kurdish fighters and their weapons from within 30 kilometres (18 miles) of the border outside the zone.
This withdrawal must be finalised within 150 hours, according to a text of the agreement released after the talks.
Russian and Turkish forces will then begin joint patrols along the Turkish-controlled zone.
Putin said the decisions were "very important, if not crucial, to allowing us to resolve the acute situation on the Syrian-Turkish border."
Erdogan had earlier threatened to resume Ankara's military offensive against Kurdish forces in Syria if they did not withdraw as agreed under a US-brokered deal.
A deadline for the withdrawal passed at 1900 GMT on Tuesday, with a Kurdish official saying they had "fully complied" ahead of the deadline.
The Turkish operation "is ending, and everything will depend now on the implementation of these agreements," Russian Foreign Minister Sergei Lavrov said in Sochi.
Turkey's assault had sparked Western outrage and accusations of betrayal from the Kurds, whose frontline fighters were crucial in the battle against the Islamic State group in Syria.
Russia is a key ally of Syria's President Bashar al-Assad and has demanded that Turkey respect the country's territorial integrity.
As the US troops began to withdraw last week, Russian forces moved in to support the Syrian army, whose help against Turkey was requested by the Kurds.
Erdogan said last week he was not bothered by the Damascus regime's return as what mattered to Ankara was pushing back the Kurdish fighters from the safe zone.
Despite being on the opposite sides of the Syria conflict, Turkey and Russia have been working together to find a solution to the war.
Tuesday's agreement said the two countries would try "to find a lasting political solution to the Syrian conflict".
It said Russia and Turkey were determined "to combat terrorism in all forms... and to disrupt separatist agendas in Syrian territory".
Ankara says the YPG is a "terrorist" offshoot of the PKK, which has been waging an insurgency inside Turkey since 1984. The PKK is blacklisted as a terrorist group by Ankara, the United States and the European Union.
The agreement said efforts would also be launched for the return of refugees to Syria "in a safe and voluntary manner".
Ankara has said some of the 3.6 million Syrian refugees in Turkey can be rehoused inside the safe zone.