A deal to prevent a Syrian government assault on Idlib, the last rebel-held province, has been hailed by all sides in the conflict for averting catastrophe for the local population of three million. The commitment of those involved to tackling militant groups still holed up in the province has also been met with approval.

On 17 September, Turkey's President Recep Tayyip Erdogan met with his Russian counterpart, Vladimir Putin, in the Black Sea city of Sochi.

The two leaders agreed on a roadmap to clear Idlib of the former al-Qaeda affiliate Hayat Tahrir al-Sham (HTS) without the need for a military intervention. According to the roadmap, both countries will create a 15-20 kilometre demilitarised zone between rebels in Idlib and Syrian government forces by 15 October.

Tehran changes

This marked a U-turn from when Putin and Erdogan met in Tehran with Iranian President Hassan Rouhani on 7 September. There, Erdogan's proposal for a ceasefire was rejected by Putin.

"The fact is that there are no representatives of the armed opposition here around this table," he said. "And more still, there are no representatives of Jabhat al-Nusra [as HTS used to be called] or IS or the Syrian army. I think in general the Turkish president is right. It would be good. But I can't speak for them, and even more so can't talk for terrorists from Jabhat al-Nusra or IS that they will stop shooting or stop using drones with bombs."

What happened in 10 days that convinced Putin to change his mind?

Turkish officials who worked on the deal and security sources who are working on the ground spoke to Middle East Eye on condition of anonymity about what happened behind the scenes.

Turkey's first offer was to start an operation in Idlib against HTS, alongside "moderate opposition groups". The plan was to create an area as it did in the northern regions of Afrin and Jarabulus, which Turkey now controls. For this scenario, Turkey promised safe passage for the government on the M5 and M4 roads, which connect Aleppo to Damascus and Latakia.

However, that was rejected by Russia, which supports the Syrian government's ambition to eliminate all the rebels and take control of all Syrian soil, including Idlib.

A Syrian child waves a Turkish flag during a demonstration against the Syrian government in the rebel-held town of Hazzanu, about 20 kilometres northwest of the city of Idlib, on September 21, 2018 (Aaref Watad / AFP) As a result, Turkish foreign and defence ministers went to Russia with a new offer: a demilitarised zone between the rebels and government forces and also a promise to clear Idlib of HTS and similar groups.

According to the sources, the deal was very close to being agreed on even before the Tehran summit, but other factors got in the way.

One was the Russia-US struggle on Syria, which led the Russian army to conduct a huge military drill in the eastern Mediterrenean in the beginning of September. Putin didn't want to publicly announce a withdrawal from a planned operation in Idlib amid this show of strength.

In addition, the US and some European nations made statements regarding the possibility of an operation against Assad if he were to use chemical weapons on civilians. Putin didn't want to step back, instead wanting to show support to Assad in Idlib, claimed Turkish sources.

What did Turkey offer?

Turkey has been working on differentiating Idlib's rebel groups from HTS for months, and has had some success. Thousands of HTS members have left the group and joined the opposition groups backed by Turkey.

Now, more than 70,000 fighters are working with Turkey in Idlib and Afrin, while HTS has nearly 15,000 members. Turkey considers the demilitarised zone a chance to convince those who supported HTS in the violent environment of Idlib to leave the group.

A security source told MEE that some members of HTS support Turkey's efforts while others oppose them. Turkish intelligence will work on playing them off against each other.

If dissolution and separation doesn't work, targeting HTS in small-scale military operations along with the other opposition groups is an alternative path.

More than 90 percent of HTS members are Syrians, and both Turkey and Russia consider them "criminal cases under Syrian government's responsibility". As a result, rebels who do not cooperate with the Turkish army on the ground and violate the deconfliction rules will be handed to the government police.

The heavy weapons and trucks of the opposition groups in the demilitarised zone will be handed to the ones in Idlib, rather than to Turkey, a high-level diplomatic source told MEE.

Turkey will also control and guarantee the security of the M5 and M4 roads, which are now held partly by HTS and the Turkey-backed opposition groups. HTS has four checkpoints on the road and Turkey-backed armed groups have two checkpoints. Turkey will eliminate all of them and will provide secure passage for government vehicles in order to let them continue trade.

A Syrian rebel fighter takes part in combat training in the Idlib countryside, 11 September 2018 (Aaref Watad / AFP) At the moment, government trucks can use the road only if they bribe the groups at checkpoints.

On 31 July, Turkey used its power over the groups in Idlib to remove a checkpoint controlled by HTS. The checkpoint was the largest controlled by HTS on the main road between Aleppo and Damascus - a crucial route for all the parties.

"We proved that we could do that back in July, and the Russians now believe that we can sucessfully remove the other four checkpoints of HTS," said the security source.

As the deal was signed by Russian and Turkish defense ministers on 17 September, and the borders of the demilitarised zone were agreed in a meeting of officials from both defence ministries in Ankara between 19 and 21 September, the Syrian government continues its operations in Idlib, but only in a limited area.

"This area is mostly within the demilitarised zone, and to clear the area from radical groups is both Turkey's and Russia's responsibility until 15 October," a Turkish official told MEE, responding to whether Turkey was uncomfortable with the government's actions.

The details of the deal are still being discussed between officials and will not be determined until the middle of October.

Refugees return to Syria

Turkish officials told Middle East Eye that Ankara plans to resettle around three million Syrian refugees currently in Turkey to northwest Syria, between Afrin and Jarabulus.

If Russia and the government conducted an operation in Idlib, Turkey would take the civilians fleeing from Idlib to those areas and there wouldn't be any place left for the ones in Turkey.

Moscow is also seeking to create a direct communication channel between Damascus and Ankara, which will be required during the political process.

A diplomatic source told MEE that they were not starting talks with the Assad regime, but in any case they are looking for ways to contact them after years of conflict.

What's next?

Turkish security sources and opposition sources on the ground say that the deal comes with risks for the opposition.

"We won't have heavy weapons in the demilitarised area, nor the regime, but the inequality comes with the Russian air forces," an opposition source in talks with Turkish intelligence in Idlib said.

"We don't have any air support here, and in case of any dispute or violation, or if Moscow thinks that radicals are still here, they can easily start an air bombardement and an assault on us. That would immediately demolish us until we get our heavy weapons back to defend ourselves."

When asked about the risks of the deal, a Turkish official said that Turkey was reinforcing and strengthening its 12 monitoring posts in Idlib, in case of such a dispute.

"We won't leave our posts there; it will help us secure what we gained on the ground when the political process starts, even if the rebels would withdraw in case of an assault," added the official from the foreign ministry.