People standing on a rooftop in Akcakale, Sanliurfa province, southeastern Turkey, at the border with Syria, watch as in the background smoke billows from fires caused by Turkish bombardment in Tal Abyad, Syria, Sunday, Oct. 13, 2019.  Turkey's official Anadolu news agency says Turkey-backed Syrian forces have advanced into the center of a Syrian border town, Tal Abyad, on the fifth day of the Turkey's military offensive against Kurdish fighters in Syria. (AP Photo/Lefteris Pitarakis)

AKCAKALE, Turkey (AP) — Syria's Kurds said Syrian government forces agreed Sunday to help them fend off Turkey's invasion — a major shift in alliances that came after President Donald Trump ordered all U.S. troops withdrawn from the northern border area amid the rapidly deepening chaos.

The shift could lead to clashes between Turkey and Syria and raises the specter of a resurgent Islamic State group as the U.S. relinquishes any remaining influence in northern Syria to President Bashar Assad and his chief backer, Russia.

Adding to the turmoil Sunday, hundreds of Islamic State families and supporters escaped from a holding camp in Syria amid the fighting between Turkish forces and the Kurds.

The fast-deteriorating situation was set in motion last week, when Trump ordered U.S. troops in northern Syria to step aside, clearing the way for an attack by Turkey, which regards the Kurds as terrorists. Since 2014, the Kurds have fought alongside the U.S. in defeating the Islamic State in Syria, and Trump's move was decried at home and abroad as a betrayal of an ally.

Over the past five days, Turkish troops and their allies have pushed their way into northern towns and villages, clashing with the Kurdish fighters over a stretch of 200 kilometers (125 miles). The offensive has displaced at least 130,000 people.

On Sunday, U.S. Defense Secretary Mark Esper said all American troops will withdraw from northern Syria because of the increasing danger of getting caught in the crossfire.

"We have American forces likely caught between two opposing advancing armies, and it's a very untenable situation," he said on CBS' "Face the Nation." He did not say how many would withdraw or where they would go but that they represent most of the 1,000 U.S. troops in Syria.

The peril to American forces was illustrated on Friday, when a small number of U.S. troops came under Turkish artillery fire at an observation post in the north. No Americans were hurt. Esper said it was unclear whether that was an accident.

Trump, in a tweet, said: "Very smart not to be involved in the intense fighting along the Turkish Border, for a change. Those that mistakenly got us into the Middle East Wars are still pushing to fight. They have no idea what a bad decision they have made."

Later in the day Sunday, Kurdish officials announced they will work with the Syrian government to fend off the Turkish invasion, deploying side by side along the border. Syrian TV said government troops were moving to the north to confront the Turkish invasion but gave no details.

The Kurdish fighters had few options after the United States abandoned them, and it had been anticipated they would turn to Assad's government for support.

A return by Assad's forces to the region where Syrian Kurds have built up autonomy in the north would be a major shift in Syria's long-running civil war, further cementing Assad's hold over the ravaged country. Late Sunday, Syrian TV broadcast from the northern town of Hassakeh where residents took to the streets to celebrate the announcement of cooperation between the Syrian government and the Kurds, and many vowed to defeat the Turkish invasion.

It would also mean that U.S. troops no longer have a presence in an area where Russia and Iranian-backed militias now have a role.

It was not clear what Russia's role was in cementing the agreement. But Russian officials have been mediating low-level talks between the Kurds and Damascus. Syria is allied with Russia, and Turkey, though it is a NATO member, has drawn close to Moscow in recent years under Turkish President Recep Tayyip Erdogan.

The U.S. withdrawal leaves open the question of what happens to the Kurdish-run prisons and detention centers that hold thousands of Islamic State prisoners, including more than 2,000 foreign militants.

On Sunday, heavy fighting reached a Kurdish-run displaced-persons camp in Ein Eissa, some 35 kilometers (20 miles) south of the border, that is home to some 12,000 people, including around 1,000 wives and widows of Islamic State fighters and their children.

The Kurdish-led administration in northern Syria said in a statement that 785 Islamic State supporters escaped after attacking guards and storming the gates. It was not immediately possible to confirm that figure.

"It gets worse by the hour," Esper said of the fighting. "These are all the exact things" that U.S. officials warned Erdogan would probably happen in urging him not to invade.

Erdogan on Sunday ruled out any mediation in the dispute with the Kurds, saying Turkey won't negotiate with "terrorists."

Turkey's official Anadolu news agency said Turkey-backed Syrian forces had advanced into the center of a Syrian border town, Tal Abyad, on the fifth day of Turkey's offensive. Turkey's Defense Ministry tweeted that its forces had taken control of the main highway running between Hassakeh, a major town and logistics hub, and Ein Eissa, the administrative center of the Kurdish-held areas.

Casualties mounted. On Sunday, at least nine people, including five civilians, were killed in Turkish airstrikes on a convoy in the Syrian border town of Ras al-Ayn, according to the Syrian Observatory for Human Rights and Syrian Kurdish officials.

Images of the attack showed bodies and severed limbs strewn in the street. Some of those killed appeared to be carrying guns. Activists said the gunmen were guarding the convoy.

Turkey said 440 Kurdish fighters have been killed since the operation began Wednesday. The SDF said 56 of its fighters have died. Turkey also said four of its soldiers were killed, along with 16 allied Syrian fighters.

___

Associated Press writer Lefteris Pitarakis reported this story in Akcakale and AP writer Sarah el Deeb reported from Beirut. AP writer Zeynep Bilginsoy in Istanbul contributed to this report.

Turkey's President Recep Tayyip Erdogan speaks to Turkish journalists, in Istanbul, Sunday, Oct. 13, 2019. Erdogan has rejected offers for mediation with Syrian Kurdish fighters as the Turkish military continues its offensive against them in northern Syria. (Presidential Press Service via AP, Pool)
In this photo taken from the Turkish side of the border between Turkey and Syria, in Akcakale, Sanliurfa province, southeastern Turkey, smoke billows from fires on targets in Tel Abyad, Syria, caused by bombardment by Turkish forces, Sunday, Oct. 13, 2019. The United Nations says at least 130,000 people have been displaced by the fighting in northeastern Syria with many more likely on the move as a Turkish offensive in the area enters its fifth day. (AP Photo/Lefteris Pitarakis)
People watch from Akcakale, Sanliurfa province, southeastern Turkey, as smoke billows from fires on targets in Tel Abyad, Syria, caused by bombardment by Turkish forces, Sunday, Oct. 13, 2019. The United Nations says at least 130,000 people have been displaced by the fighting in northeastern Syria with many more likely on the move as a Turkish offensive in the area enters its fifth day.(AP Photo/Lefteris Pitarakis)
In this photo taken from the Turkish side of the border between Turkey and Syria, in Akcakale, Sanliurfa province, southeastern Turkey, Turkish-backed Syrian opposition fighters celebrate in Tal Abyad, Syria, Sunday, Oct. 13, 2019. State-run Anadolu news agency reported Tal Abyad had fallen to a Turkish military offensive on Sunday. Even after the announcement, sporadic gunfire and the occasional mortar round could still be heard in the town, which is on the border with Turkey, while smoke could be seen rising from several points in the town. (AP Photo/Cavit Ozgul)
In this photo taken from the Turkish side of the border between Turkey and Syria, in Akcakale, Sanliurfa province, southeastern Turkey, Turkish-backed Syrian opposition fighters on pick-up trucks celebrate as they drive in Tal Abyad, Syria, Sunday, Oct. 13, 2019. State-run Anadolu news agency reported Tal Abyad had fallen to a Turkish military offensive on Sunday. Even after the announcement, sporadic gunfire and the occasional mortar round could still be heard in the town, which is on the border with Turkey, while smoke could be seen rising from several points in the town. (AP Photo/Cavit Ozgul)
In this Saturday, Oct. 12, 2019 photo, Turkey-backed Syrian fighter stand in Ras al-Yan, Syria.Turkey's military says it has captured a key Syrian border town Ras al-Ayn under heavy bombardment in its most significant gain as its offensive against Kurdish fighters presses into its fourth day. (AP Photo)
In this Saturday, Oct. 12, 2019 photo, Turkey-backed Syrian fighters enter Ras al-Yan, Syria.Turkey's military says it has captured a key Syrian border town Ras al-Ayn under heavy bombardment in its most significant gain as its offensive against Kurdish fighters presses into its fourth day. (AP Photo)
In this Saturday, Oct. 12, 2019 photo, Turkey-backed Syrian fighters enter Ras al-Yan, Syria.Turkey's military says it has captured a key Syrian border town Ras al-Ayn under heavy bombardment in its most significant gain as its offensive against Kurdish fighters presses into its fourth day. (AP Photo)
In this Saturday, Oct. 12, 2019 photo, Turkey-backed Syrian fighters enter Ras al-Yan, Syria.Turkey's military says it has captured a key Syrian border town Ras al-Ayn under heavy bombardment in its most significant gain as its offensive against Kurdish fighters presses into its fourth day. (AP Photo)
A child stands across from a building damaged by a mortar fired from inside Syra, in Akcakale, Sanliurfa province, southeastern Turkey, Sunday, Oct. 13, 2019. Incoming shells fired from northeastern Syria hit the house earlier on Sunday. Two residents were at the house and were evacuated. (AP Photo/Lefteris Pitarakis)
People are seen through a hole in a building damaged by a mortar fired from inside Syria, in Akcakale, Sanliurfa province, southeastern Turkey, Sunday, Oct. 13, 2019. Incoming shells fired from northeastern Syria hit the house earlier on Sunday. Two residents were at the house and were evacuated. (AP Photo/Lefteris Pitarakis)
A person inspects the damage on a building hit by a mortar fired from inside Syria, in Akcakale, Sanliurfa province, southeastern Turkey, Sunday, Oct. 13, 2019. Incoming shells fired from northeastern Syria hit the house earlier on Sunday. Two residents were at the house and were evacuated. (AP Photo/Lefteris Pitarakis)
People are seen through a shattered window on a building damaged by a mortar fired from inside Syria, in Akcakale, Sanliurfa province, southeastern Turkey, Sunday, Oct. 13, 2019. Incoming shells fired from northeastern Syria hit the house earlier on Sunday. Two residents were at the house and were evacuated. (AP Photo/Lefteris Pitarakis)
In this photo taken from the Turkish side of the border between Turkey and Syria, in Akcakale, Sanliurfa province, southeastern Turkey, smoke billows from fires on targets in Tel Abyad, Syria, caused by bombardment by Turkish forces, Sunday, Oct. 13, 2019. The United Nations says at least 130,000 people have been displaced by the fighting in northeastern Syria with many more likely on the move as a Turkish offensive in the area enters its fifth day.(AP Photo/Lefteris Pitarakis)
A man watches from Akcakale, Sanliurfa province, southeastern Turkey, as smoke billows from targets in Tel Abyad, Syria, during bombardment by Turkish forces, Sunday, Oct. 13, 2019. The United Nations says at least 130,000 people have been displaced by the fighting in northeastern Syria with many more likely on the move as a Turkish offensive in the area enters its fifth day.(AP Photo/Lefteris Pitarakis)