ANKARA/AMMAN (Reuters) - Turkey will send more troops into Syria’s Idlib province after striking a deal with Russia that has averted a government offensive and delighted rebels who said it kept the area out of President Bashar al-Assad’s hands.

The deal unveiled on Monday by Russian President Vladimir Putin, Assad’s most powerful ally, and Turkish President Tayyip Erdogan will create a demilitarized zone from which “radical” rebels must withdraw by the middle of next month.

Damascus also welcomed the agreement but vowed to continue its efforts to recover “every inch” of Syria. Iran, Assad’s other main ally, said that “responsible diplomacy” had averted a war in Idlib “with a firm commitment to fight extremist terror”.

The agreement halted a threatened Syrian government offensive. The United Nations had warned such an attack would create a humanitarian catastrophe in the Idlib region, home to about 3 million people.

The Idlib region and adjoining territory north of Aleppo represent the opposition’s last big foothold in Syria. Assad has recovered most of the areas once held by the rebels, with decisive military support from Iran and Russia.

But his plans to recover the northwest have been complicated by Turkey’s role on the ground. It has soldiers at 12 locations in Idlib and supplies weapons to some of the rebels.

Erdogan had feared another exodus of refugees to join the 3.5 million already in Turkey, and warned against any attack.

In striking the deal, Russia appears - at least for now - to have put its ties with Turkey ahead of advancing the goal of bringing all Syria back under Assad’s rule.

That goal is also obstructed by the presence of U.S. forces in the quarter of Syria east of the Euphrates that is held by an alliance of Kurdish and Arab militias, and at a base near the borders with Jordan and Iraq.

U.S. Defense Secretary Jim Mattis played down any notion the Turkey-Russia agreement had resolved the situation in Idlib.

“Idlib is one of the most complex problems in a complex theater (of conflict) right now. So I’m quite sure it’s not all sorted,” Mattis told reporters at the Pentagon.

Analysts cautioned that implementation of the deal faced big challenges, notably how to separate jihadists from other rebels - a goal Ankara has been struggling to achieve.

Turkish Foreign Minister Mevlut Cavusoglu said the “moderate opposition” would keep its weapons and the “region will be cleared of radicals”. Turkey would “make additional troop deployments” and its 12 observation posts would remain.

The deal was “very important for the political resolution in Syria”. “If this (Idlib) had been lost too, there would be no opposition anymore,” he said.

Mustafa Sejari, a Free Syria Army (FSA) official, said the deal “buries Assad’s dreams of imposing his full control over Syria”.

Yahya al-Aridi, spokesman for the opposition Syrian Negotiations Commission, expressed hope a government offensive was now off the table for good.

The Syrian government, in a statement published by state media, said it welcomed any agreement that spared blood. It also said the deal had a specific time frame, which it did not detail.

FILE PHOTO: People inspect the damage at a site hit by airstrikes in the rebel-held city of Idlib, Syria February 7, 2017. REUTERS/Ammar Abdullah

“I see it as a test of the extent of Turkey’s ability to implement this decision,” Ali Abdul Karim, Syria’s ambassador to Lebanon, said in an interview with Lebanon’s al-Jadeed TV. “We do not trust Turkey ... but it’s useful for Turkey to be able to carry out this fight to rid these groups from their weapons.”

‘CATASTROPHE’ AVERTED

Moscow said the deal “confirmed the ability of both Moscow and Ankara to compromise ... in the interests of the ultimate goal of a Syrian settlement by political and diplomatic means”.

“Is this merely a stay of execution? Or is it the beginning of a reprieve?” U.N. aid chief Mark Lowcock asked during a monthly meeting of the U.N. Security Council on Syria.

The demilitarized zone will be monitored by Russian and Turkish forces, the countries’ leaders said.

Neither Russia nor Turkey has explained how it plans to differentiate “radically minded” rebels from other anti-Assad groups. It was also not immediately clear how much of the city of Idlib fell within the zone.

Putin said the decision was to establish by Oct. 15 a demilitarized area 15 to 20 km (10-12 miles) deep along the contact line between rebel and government fighters.

Naji Abu Hufaiza, spokesman for the National Front for Liberation, said he did not have details of the agreement, but added that while he saw it as a success for Turkish diplomacy, his group did not trust Russia to uphold it.

Idlib is held by an array of rebels. The most powerful is Tahrir al-Sham, an amalgamation of Islamist groups dominated by the former Nusra Front - an al Qaeda affiliate until 2016.

Other Islamists, and groups fighting as the Free Syrian Army banner, are now gathered with Turkish backing under the banner of the “National Front for Liberation”.

The area is also the last major haven for foreign jihadists who came to Syria to fight the Alawite-led Assad government.

Putin said that, at Erdogan’s suggestion, by Oct. 10, all opposition heavy weapons, mortars, tanks, rocket systems would also be removed from the demilitarized zone.

Earlier this month, Putin publicly rebuffed a proposal from Erdogan for a truce when the two met along with Iran’s president at a summit in Tehran.