Turkey and Russia have agreed to the removal of Kurdish militants from a buffer zone in north-east Syria and to conduct joint patrols in the area as part of a deal that reinforces the two countries' sway over the region.
In a joint statement after more than five hours of talks in Russia, the Turkish president Recep Tayyip Erdogan and Vladimir Putin, his Russian counterpart, said Kurdish forces would have 150 hours to fully withdraw from a depth of 30km from the Turkish-Syrian border.
The deal follows on a previous five-day truce brokered by the US that halted a Turkish offensive in the region, which expired on Tuesday. It will lead to the Syrian regime and Russian forces extending their control to territory from which American troops have withdrawn, underlining how the Turkish intervention has shifted the dynamics in Syria.
Russia's role in Syria has become pivotal. Its 2015 intervention in the eight-year Syrian civil war enabled president Bashar al-Assad's regime to reassert control over much of the country.
Mr Erdogan described Tuesday's agreement made in the Black Sea resort town of Sochi as an "historic understanding".
Turkey launched the offensive into north-east Syria on October 9 after President Donald Trump withdrew US troops, who had fought alongside the Kurdish militants in the battle against Isis, from the border region. Ankara has long pressed for the establishment of what it describes as a "safe zone" along the Turkish frontier, which would be cleared of the Kurdish militants.
Turkey considers the Kurdish fighters to be terrorists and does not distinguish between them and the Kurdistan Workers' party, or PKK, which has been fighting a more than three-decade insurgency against the Turkish state. But Ankara's intervention triggered an international outcry amid fears it would create a humanitarian crisis and lead to the resurgence of Isis in the area.
Scores of people have been killed in the offensive, more than 165,000 people were forced to flee their homes and Isis affiliates that were detained by the Kurdish militants have escaped.
The Kurdish-dominated Syrian Democratic Forces said on Tuesday it had already withdrawn from the border region between the towns of Tel Abyad and Ras al-Ain as part of the US-brokered truce. But Mr Erdogan signalled he was not fully satisfied with the SDF's withdrawal. He was quoted as telling reporters on the plane back from Sochi: "The promises that were made were not fully delivered . . . We will take the steps that are necessary. If we make concessions, we will pave the way for the terrorists."
Mr Trump initially appeared to give Mr Erdogan the green light for the offensive, but after facing criticism from within his Republican party for abandoning America's Kurdish allies, he imposed sanctions on Turkey and threatened to "destroy" the Turkish economy. Washington said it would lift the sanctions if Ankara complied with the US truce.
Mr Erdogan's plans to control the safe zone were complicated after the SDF struck a deal with the Assad regime, which meant Syrian government forces, backed by Russia, were able to re-enter the north-east for the first time in years. Turkey has been the main backer of the opposition during Syria's civil war, but analysts say the deal could hasten Ankara's re-engagement with Damascus.
"This is the logical end of the Turkish war in Syria but the price is the de facto recognition of the Assad government. Erdogan had a choice put in front of him - the PKK or Assad - and he chose Assad," said Aaron Stein, director of the Middle East Program at the Foreign Policy Research Institute in Philadelphia. "Syria is now the playground of Moscow, Ankara and Tehran."
Mr Erdogan has also achieved his goal of breaking the alliance between the Kurdish forces and the US, Mr Stein added.
Under the deal reached on Tuesday, Syrian and Russian forces will "facilitate" the removal of Kurdish fighters and their weapons within a week. After that, joint Turkish-Russian patrols will begin outside the zone between Tel Abyad and Ras al-Ain.
"Both countries will take the necessary precautions to prevent terrorist infiltrations and will establish a joint mechanism to monitor and co-ordinate the agreement," Mr Erdogan said.
The agreement suggests the Turkish president will not get the full safe zone he envisaged stretching 440km along the border. The border town of Qamishli will not be included, the statement said. But Kurdish fighters will be forced to pull back from Manbij - a strategic city where US troops were based before Mr Trump announced he was pulling the remaining 1,000 American soldiers out of Syria.
On Monday Mark Esper, US secretary of defence, said the Trump administration was considering leaving some troops behind in north-east Syria to secure oilfields and protect them from Isis militants. Mr Esper did not elaborate on potential troop numbers. A senior administration official confirmed on Tuesday that the US was "reviewing all options" with respect to leaving troops in the north-east.
Critics, including some US senators, have said Mr Trump's decision to withdraw American troops so abruptly has set a dangerous precedent of the Trump administration abandoning its local allies, and hands a strategic victory to the Assad regime and its foreign backers, Russia and Iran.