Turkey and Russia announced a ceasefire in northern Syria on Thursday, agreeing to end weeks of heavy fighting that sparked a humanitarian disaster and raised fears of their armies clashing.
After more than six hours of talks in Moscow, Russian President Vladimir Putin and Turkish counterpart Recep Tayyip Erdogan agreed on the ceasefire to take effect from midnight on Friday.
The agreement will also create a security corridor along the key M4 highway in northern Syria, where Turkish and Russian forces will launch joint patrols from March 15.
The deal aims to put a stop to intense fighting in Idlib, the northwestern province of Syria where Ankara is battling Moscow-backed government forces.
Nearly a million civilians have fled their homes due to the violence and dozens of Turkish soldiers have been killed.
Putin told a joint press conference after the talks that the agreement would "serve as a good basis for ending fighting" in Idlib and for "stopping the suffering of the civilian population."
"The object is to avoid the humanitarian crisis getting worse," Erdogan said, though he added that Turkey reserved the right to "retaliate with all its strength against any attack" by Damascus.
The situation in Idlib, the last rebel stronghold in Syria's nine-year civil war, had become critical as Ankara for the first time launched a direct offensive against President Bashar al-Assad's forces.
Turkey has long backed certain rebel groups against Assad but its priority now is to stop an influx of refugees among those fleeing an offensive the regime has been pressing on Idlib since December.
Ankara has demanded the European Union support its actions in Syria and last week opened its border with Greece to migrants -- a move decried by some in the bloc as "blackmail."
Despite supporting opposing sides in the war, Russia and Turkey have worked to try to resolve the conflict and avoid direct confrontation.
The two countries agreed a deal in the southern Russian city of Sochi in 2018 that created a "de-escalation" zone in Idlib and allowed for the deployment of 12 Turkish observation posts.
In the run-up to Thursday's talks, the two sides had traded accusations of violating the deal.
Ankara said Russia was not fulfilling part of the agreement that guaranteed no attacks on Idlib and the status quo on the ground.
Moscow in turn said Turkey was breaching the agreement by supporting "illegal armed groups" and accused Turkish forces of mingling with "terrorists" in Idlib.
Turkey officially declared an operation against the Assad government over the weekend, after 34 Turkish soldiers died in an air strike blamed on Damascus.
It has since downed three Syrian warplanes and killed dozens of soldiers and allied fighters, according to monitors.
Fighting continued in the province on Thursday, with Russian air strikes killing at least 15 civilians gathered outside the town of Maaret Misrin, the Syrian Observatory for Human Rights monitoring group said.
Erdogan warned Europe on Wednesday that it must support Turkey's "political and humanitarian solutions in Syria" if it wants to avoid a repeat of the 2015 migration crisis.
Thousands of migrants have massed at the Turkish-Greek border since Erdogan gave them the green light to try to enter Europe, leading to clashes with Greek police.
Turkey hosts roughly 3.6 million refugees from Syria — and hundreds of thousands from elsewhere — and Erdogan's move has sparked concern in Europe of a renewed influx of migrants.