Russia and Turkey have said they have agreed to a ceasefire in Syria’s Idlib province after clashes left scores of Turkish and Syrian soldiers dead in a dangerous escalation of violence.

Speaking at the Kremlin, Russia’s Vladimir Putin and Turkey’s Recep Tayyip Erdoğan announced that the ceasefire would begin at midnight on Thursday evening and that they hoped it would defuse tensions in the region.

The three-point agreement, read out by the two countries’ foreign ministers, also stipulated the creation of a seven-mile (12km) “safety corridor” along the country’s crucial M4 highway, which Russian and Turkish forces would begin patrolling at the end of next week.

The agreement would effectively preserve some of the territorial gains made by Russian-backed Syrian forces during a three-month offensive in Idlib, the country’s last remaining rebel stronghold, while preserving a Turkish foothold in the region.

The deal was hammered out after six hours of talks between Erdoğan and Putin. Putin called the talks “tense, difficult but constructive”.

The two leaders also called for further negotiations to limit the humanitarian crisis in the region and facilitate the return of refugees to their homes. More than a million people are said to have been displaced since Syria launched its offensive in Idlib province in December.

However, the ceasefire is likely to be fragile. Speaking to the press, Erdoğan said Turkey’s military would have the right to respond if it was attacked by Syrian government forces.

Erdoğan went to the Kremlin on Thursday to try to broker a ceasefire with Putin to stem mounting military losses and prevent another large influx of refugees fleeing Idlib province.

The two countries are on rival sides of Syria’s war, with Russia supporting the Syrian government of Bashar al-Assad and Turkey backing anti-government fighters. Russia and Syria have accused Turkey of backing “terrorists”.

Turkey had sent thousands of troops into Syria to halt a Syrian offensive aimed at retaking territory in Idlib province. That led to direct clashes between the two regional powers. At least 58 Turkish soldiers have died in the fighting, including 33 that were killed last week in a single airstrike.

Turkey has retaliated against Syrian forces with drone and artillery strikes, and shot down several Syrian warplanes, probably killing more than 150 Syrian soldiers and other fighters aligned with Assad.

Putin began the talks on Thursday by expressing his condolences for the Turkish forces killed in airstrikes in Syria, saying that both Russian and Syrian forces were unaware of their locations. Erdoğan said he hoped the talks would “ease the situation”.

Russia, which has provided military support to Syria’s government since 2015, initially avoided taking part in the conflict, apparently to prevent an escalation with Ankara. But it re-entered the battle on Monday, helping Syria to retake the strategic town of Saraqeb and deploying its military police to prevent Turkish reprisals.

Erdoğan probably wanted to halt Assad’s offensive in Idlib and retain territory under its de facto control under a 2018 agreement brokered by Russia. Russia wants to restore an equilibrium in the region, probably reflecting territorial gains made by the Syrian army, without spoiling its relations with Turkey.

The renewed struggle for Idlib province has exacerbated the region’s refugee crisis. According to the UN, the Syrian offensive has had “catastrophic” humanitarian consequences, driving an estimated 1 million refugees from their homes since it began in December. Three million more are said to be trapped in Idlib.

In an attempt to put pressure on Europe, Erdoğan dramatically threw open Turkey’s borders with Greece and said his country would no longer prevent migrants from travelling to the EU. Since then, thousands of refugees have gone to the border with the EU. Several European officials have accused Ankara of attempting to “blackmail” them by using the threat of migrant flows to extort greater political backing in talks with Moscow.

The humanitarian crisis in Turkey shines a light on Europe’s failures | Elif Shafak Read more

Ankara claimed on Thursday it had deployed 1,000 police special forces along the border with Greece, and that scores of people had been injured by Greek guards trying to stop them from crossing into the country.

Putin has sought to play the role of powerbroker in Syria’s conflict, both by propping up the Assad government and by organising a series of talks with regional players Turkey and Iran to negotiate an end to the conflict.

But Russia has also sought to court Turkey as a potential counterweight to western influence in the region. Erdoğan has openly feuded with Washington since a 2016 coup attempt against him, saying that the west has backed his political opposition, and he angered the alliance by purchasing the S-400 missile defence system from Moscow last year, rather than US-made Patriot missiles.