IN THE spring of 2015 the rebel takeover of Idlib province in north-western Syria seemed to signal the beginning of the end for President Bashar al-Assad. Yet Idlib’s fall may have saved him. Fearful of losing his close ally, Russia’s president, Vladimir Putin, decided to join the fray. Within months of Idlib’s capture, Russian aircraft were battering rebel lines. Russia’s entry into the war proved a turning-point. Forces loyal to Mr Assad have since beaten back the rebels on every front, boxing them into ever-shrinking pockets of territory. In December Mr Assad’s men turned their guns on Idlib, the last province under complete rebel control. It may now provide the backdrop for the end of the uprising.

For a time it had seemed as if Idlib, a province of 2.6m people, might escape the fighting. It is dominated by rebels, including Hayat Tahrir al-Sham (HTS), a group linked to al-Qaeda. But a ceasefire hashed out in September between Turkey, which has backed the rebellion, and the regime’s allies, Iran and Russia, dampened the violence. Turkey sent troops to the province in October to monitor the truce, which excluded HTS. Russian military police were supposed to follow. Both countries had agreed to curb HTS’s power in the province (see map).

As part of the deal, Turkey was to have forced the rebels it backs to hand over parts of eastern Idlib to the regime. In return, the Turks won Russian approval to enter Idlib and to set up bases around the Kurdish-run enclave of Afrin, which lies near the Turkish border. Turkey views the Kurds who rule that area, and who have seized a quarter of the country since the start of the war, as a branch of the Kurdistan Workers’ Party (PKK), a group it has fought for decades and calls terrorists. Turkey repeatedly says it will not allow the Kurds to form a “terror corridor” on its border.

But the Syrian regime and its Russian backers have grown frustrated with Turkey’s failure to uphold its end of the bargain. HTS fighters refuse to leave eastern Idlib. So in December Mr Assad’s forces, with Russian air cover, pushed eastwards along a railway line, shrinking the rebels’ enclave as they captured a string of villages. The regime is close to retaking a large air base and may press on to seize a strategic road running through Idlib and linking some of Syria’s biggest cities. More than 200,000 people have fled the violence. Turkey fears the fighting could drive many Syrians across its border to join the 3.4m refugees it already harbours.

The incursion could derail the rapprochement between Turkey and Russia, casting doubt on Russia’s ability to mediate an end to the war. Relations between the two countries, which back opposing sides in the war, had begun to warm. Turkey had agreed to cut back its support for the rebels in return for Russia’s assent to a Turkish military operation in 2016 that split the Kurds’ territory in two. More recently, the two countries had worked together to create four “de-escalation” zones where rebels and the regime’s troops were supposed to stop killing each other. The agreement was meant to pave the way for Russian-led peace talks.

Since Mr Assad’s forces entered Idlib, however, Turkey has sounded less happy with Russia’s vision for post-war Syria. In December President Recep Tayyip Erdogan called Mr Assad a terrorist and said the Syrian president had no role in Syria’s future, a view at odds with Russia’s. Mr Erdogan’s comment implied a warning to Russia that he could scuttle Russian-led peace talks, should the Kurds be allowed to take part. On January 13th Turkey raised the stakes by announcing that a ground operation to seize Afrin, where Russian troops are based, would begin “in the coming days”.

This may mess up Russia’s plans to host a peace conference in the Black Sea resort of Sochi later this month. Russia has already asked various Kurds to the talks, which have been postponed twice, but has steered clear of asking any from the Kurdish party that runs the area that includes Afrin, in order to allay Turkish concerns.

Western governments and Syria’s opposition leaders see the Sochi conference as Russia’s attempt to undermine UN-sponsored peace talks in Geneva that have gone nowhere, snagged on Mr Assad’s fate. But the more territory he captures, the less willing he will be to negotiate an end to his own rule.