MOSCOW — After six hours of talks at the Kremlin, the presidents of Russia and Turkey on Thursday announced what they said was a deal to halt fighting in the Syrian region of Idlib, calming a volatile conflict that had pushed the two countries to the brink of open war.

They said the agreement included a cease-fire that would come into force in Idlib, the last stronghold of Syrian rebels, at midnight. The agreement also included joint patrols by Russian and Turkish troops of a seven-mile wide corridor along a highway that runs through Idlib eastward from the Mediterranean coast toward the border with Iraq.

Idlib, in northwestern Syria, has been the scene of intense fighting in recent weeks as the Russian-backed forces of Syria’s president, Bashar al-Assad, have moved to expel the last rebels. The fighting there last week killed at least 34 soldiers from Turkey, which supports the rebels, and has sent hundreds of thousands of Syrian refugees fleeing toward the closed border with Turkey, which is already hosting more than three million Syrians.

“We do not always agree with our Turkish partners in our assessments of what is happening in Syria, but each time at critical moments, relying on the achieved high level of bilateral relations, we have thus far managed to find common ground on the disputed issues that have arisen, and come to acceptable solutions,” President Vladimir V. Putin of Russia said late Thursday in the Kremlin, standing alongside Turkey’s president, Recep Tayyip Erdogan. “That’s what happened this time too.”