Turkey and Russia have agreed what they called a "historic" deal over military action against Kurds in northern Syria after a marathon diplomatic meeting.
The two powers had both stationed troops on the Turkey-Syria border after United States troops withdrew from the area.
Turkey launched an offensive against Syrian Kurdish militias, some of whom it considers a terrorist group.
Now, Russia and Turkey will conduct joint patrols on the border, changing the power dynamic in the area.
The new deal came just ahead of the expiry of a ceasefire between Kurdish fighters and Turkish forces which had been brokered by the United States.
Kurdish fighters said they had completed their withdrawal under that agreement, but the deal agreed by Turkey with Russia has effectively extended it.
They have been given another 150 hours to withdraw to a depth of 32km from the border - a so-called "safe zone".
The Kurdish forces in northern Syria are dominated by the Kurdish People's Protection Units (YPG) militia, which Turkey considers a threat lying on its border.
The deal effectively splits military control of the region between Russia and Turkey, filling a role left vacant by the United States' sudden and unexpected withdrawal.
Fears of clashes between Russia and Turkey
After the US forces - which had been allies to the Kurds fighting the Islamic State group - withdrew, Mr Erdogan launched a cross-border offensive on 9 October.
Russia, allied to Syria's president, stationed troops near the border over concerns that Syria's territory was being encroached upon by a foreign power.
The Russian deployment had created the potential for clashes between Russia and Turkey - something Mr Erdogan and Mr Putin both want to avoid.
But after six hours in a private meeting between Mr Erdogan and Mr Putin, the two sides agreed a deal.
Russia has agreed to allow Turkey's operation, removing the risk of conflict between the two sides.
The area in question is a 120km-long strip between the towns of Ras al-Ain to Tal Abyad, where the Turkish operation is taking place.
But Mr Erdogan had reportedly wanted all 440km of the border to be part of the safe zone.
The statement from Russia and Turkey says that Kurdish forces "will be removed" from the towns of Manbij and Tal Rifat - both of which lie outside the operation area.
Kurdish militias have yet to indicate whether they will agree to those demands.
US envoy says things 'better' in Syria
Prospects for an end to Turkey's offensive against Kurdish fighters in Syria were better than a week ago, US President Donald Trump's special envoy for Syria said today, but a permanent ceasefire would depend on both sides meeting the terms of last week's temporary ceasefire agreement.
"We're in a better place now than we were a week ago," special envoy James Jeffrey told a Senate hearing where both Democrats and Mr Trump's fellow Republicans lawmakers criticised Mr Trump's policies.
"In looking at this ceasefire, I think we have done a pretty good job in bringing this conflict to a halt," Mr Jeffrey said.
He said Turkey's military had agreed to a more permanent "pause" in the fighting, if Kurdish fighters withdrew from territory as spelled out in last week's agreement. The five-day ceasefire expired on Tuesday.
US sanctions on Ankara would be eased only if Turkey stopped the offensive, Mr Jeffrey said.
The Republican-led Senate Foreign Relations committee called Mr Jeffrey to testify two weeks after Mr Trump abruptly announced that he was removing US troops from Syria, clearing the way for Turkey's offensive against the Kurds and changing the course of the more than eight-year-long Syrian war.
Committee members from both parties raised concerns that the United States had lost leverage over Ankara, "abandoned" Kurdish fighters who had helped battle Islamic State militants and about the danger of increased instability in a volatile region.
The Kurds ran prisons holding Islamic State fighters. Roughly 10,000 Islamic State detainees were at risk of release if "things go south" in northern Syria, Mr Jeffrey said. He estimated dozens had got out so far.
Several senators mentioned the possibility that NATO ally Turkey would carry out "ethnic cleansing" of the Kurds.
Mr Jeffrey is due to testify to the Democratic-led House of Representatives Foreign Affairs Committee tomorrow (US time).
"Were the United States to sit back, while Turkey attempted to slaughter the Kurds, I think that would be disgraceful," Republican Senator Ted Cruz said.
Mr Jeffrey said he was not consulted about Trump's plan to withdraw troops. He said he was "personally furious" about Turkey's offensive, but said Turkey remains a democracy that shares many US values and is not an international rival.
The panel's Republican chairman, Senator Jim Risch, said sanctions must be imposed on Turkey if it continues its offensive.
"If Turkey maintains its aggressive path, it must bear a cost for undermining US security interests," Mr Risch said.
Republican Senator Marco Rubio said he did not believe Turkey seeks only a "safe zone" in northern Syria. President Erdogan wants a permanent territory with very few Kurdish residents where Syrian refugees could be returned from Turkey, Mr Rubio said.
- BBC / Reuters