ISTANBUL - Turkish President Recep Tayyip Erdogan and his Russian counterpart Vladimir Putin say they have reached an agreement that averts a looming military offensive on the Syrian rebel-held Idlib enclave.

"We will prevent a humanitarian tragedy which could happen as a result of military action," Erdogan said after Monday's talks at the Russian Black Sea Sochi resort.

Erdogan, Putin Strike Deal on Idlib Demilitarized Zone

The two leaders agreed to create a 15 to 20 kilometer demilitarized zone in the Syrian enclave. Putin claimed the agreement would remove the threat to the Russian Hmeimim military airbase, which has been targeted by rebels, including using drones.

Erdogan, Putin Strike Deal on Idlib Demilitarized Zone

Putin said Russian and Turkish forces would enforce the demilitarized zone, which would see the removal of the rebels' heavy weapons as well as the "withdrawal of all radical fighters" from Idlib, including the Al-Nusra Front.

Erdogan, Putin Strike Deal on Idlib Demilitarized Zone

Syrian forces, backed by Russian airpower, were threatening to overrun Idlib — the last rebel stronghold. Erdogan has warned of a looming "bloodbath." On Monday, he said the "world was looking at Sochi" to avert a humanitarian crisis.

A top U.S. official Wednesday called the talks between Russia and Turkey "encouraging."

"The discussions that they're having lead us down a path the potential that you're going to get something that's less kinetic [based on military action]," Defense Intelligence Agency Director, Lt. Gen. Robert Ashley, told an audience in Washington.

A military campaign "does no good for the long term of Syria because all it does is continue to add to the human suffering," he said. "We want to see the factions and the different parties come together to be able to start to look at a way we can start setting peace and start working to a sense of normalcy."

Up to 3 million civilians are believed to be trapped in the enclave, along with tens of thousands of rebel fighters, including jihadis linked to al-Qaida and the so-called Islamic State.

Erdogan said Monday's agreement underscored the importance of the two countries' deepening ties.

Turkish media reported that Russian Defense Minister Sergei Shoigu said a deal would soon be reached by Russian and Syrian forces to end airstrikes on Idlib.

The Sochi meeting is being viewed as a diplomatic success for Erdogan.

"We can say this is a success, as there is a new timeline of the 15th of October, when the heavy weapons have to be evacuated [from the demilitarized zone]," said former senior Turkish diplomat Aydin Selcen, who served across the region.

"The mere fact that this meeting in Sochi could have happened — the two leaders being of the same mind as much as possible — this tells me this Russian-Turkish relationship is still very much alive," he added."

Securing more time for Idlib was a key priority for Ankara.

"It's asking for more time to find a nonmilitary solution to the Idlib conundrum," said Sinan Ulgen, head of the Edam think tank.

Ankara fears any attack on Idlib would see hundreds of thousands of refugees fleeing across the border. With over 3 million Syrian refugees in Turkey, Erdogan said the country could not take any more.

Damascus, supported by Moscow, claims the Idlib region is a center of terrorism, which threatens the whole country.

At a summit in Tehran earlier this month with Putin and Iranian President Hassan Rouhani, Erdogan proposed that Turkish forces help to differentiate rebels from designated terrorist organizations in Idlib. Putin dismissed the proposal.

Despite backing opposite sides, Ankara and Moscow have been cooperating with Tehran to end the Syrian civil war. The process was initiated in the Kazakh capital of Astana, focusing mainly on resolving battlefield issues.

Turkish-Russian cooperation on Syria is the springboard for broader deepening ties, causing concern among Turkey's NATO allies.

"If we witnessed such an operation against Idlib, it would undermine Turkey's trust in Russia," Ulgen said.

Analysts suggest Putin's apparent accommodation of Erdogan is likely motivated by his broader strategic goal of continuing to foment tensions in NATO by courting Erdogan.

"Right after this meeting in Sochi, President Erdogan will be traveling to New York," Selcen noted. "And so, maybe Putin felt he had to sweeten this relationship enough, so not to push Turkey towards the American side once again."

U.S.-Turkish relations remain deeply strained over a myriad of differences. However, the two sides share common ground opposing Damascus's threatened Idlib operation.

Ankara has also been reinforcing its armed presence in the rebel enclave. Under an agreement with Moscow and Tehran, Turkey has established 12 military observation posts in Idlib.