Beirut- A pair of dusty villages in the Syrian desert are all that remain of the vast expanse of territory Daesh once called its caliphate, and the complete territorial defeat of the militant group appears to be imminent, according to US and Kurdish officials.

A few hundred of some of the most die-hard Daesh fighters are making their last stand in the villages of Marashida and Baghuz Fawqani on the banks of the Euphrates River, a few miles from the Iraqi border in southeastern Syria. With the Syrian regime’s army on the other side of the river, a group that once controlled an area the size of Britain is pinned down by the US-backed Syrian Democratic Forces in a dot of land measuring 6 square miles.

It is now only a matter of weeks or even days before the villages are overrun and Daesh’s vaunted state-building enterprise in Syria and Iraq is brought to an end, military officials say.

The conclusion of the 4 1/2-year war will add urgency to the question of when and how the United States will pull its forces out of Syria, as ordered by President Donald Trump last month. He later said they would remain to finish the fight against Daesh, and still no date has been set for their withdrawal.

Col. Sean Ryan, the US military spokesman in Baghdad, cautioned that the end of the war on the ground will not halt the threat posed by Daesh, which is trying to regroup as an insurgent force in many of the areas where it has lost control.

Although the military has withdrawn some equipment, no troops have left and no deadline for a pull out has been issued, he said. In the meantime, US troops will be focusing on training their local partners and stabilising the area to deter a return of the militants.

“The end is near territorial-wise, but they will continue to regroup and, like we’ve seen over the past two weeks, will try to create spectacular events,” Ryan said, referring to the suicide bombing at a restaurant in the town of Manbij last week, which killed four Americans. It came more than three years after Daesh had been driven out of that area.

The holdouts in the two desert villages include some of the most committed extremists, who have remained on the battlefield despite multiple opportunities to escape or surrender and can be expected to fight until the end.

But if the campaign by US-backed forces proceeds as well as it has in recent days, it could be over within as little as two weeks, Ryan said. Mazloum Kobani, the top commander of the SDF, told Agence France-Presse on Friday that it would take no more than a month.

“I believe that during the next month we will officially announce the end of the military presence on the ground of the so-called caliphate,” Kobani said.

The remaining militants include some of Daesh’s most senior leaders and “famous terrorists,” according to Zana Amedi, a spokesman for the Kurdish People’s Protection Units, or YPG, which is the biggest component of the SDF.

US and Kurdish officials do not believe, however, that Abu Bakr Al Baghdadi, Daesh leader, is among them. “He would have to be stupid to stay in the last pocket until the end,” said Amedi. “He would have escaped a long time ago before the situation deteriorated for them so much. He’s not dead, and he’s not in these villages either.”

A big percentage of those who remain are foreigners who flocked to Syria to join Daesh when it was at the peak of its power. Because of their appearance, they would stand out among the locals if they tried to blend in with the civilians fleeing the battlefield, as some local fighters have done.

“They have no choice but to fight to the death or surrender,” Amedi said.

Dozens of foreigners are among scores of fighters who have surrendered or have been caught trying to escape over the past week, Amedi said. A majority of the foreigners are Iraqis, but there are also Europeans, Americans and Asians among them.

Thousands of civilians have also been streaming out of the area and handing themselves over at SDF checkpoints, where they are screened for Daesh fighters trying to hide among them, he said.

Civilians have been dying too - in the crossfire, at the hands of Daesh snipers who seek to prevent them from escaping and in the US-led airstrikes providing the muscle behind the offensive.

The US military said on Friday it has launched an investigation into what appears to have been one of the worst incidents. As many as 39 civilians were killed in the town of Baghouz on Tuesday when vehicles in which they were trying to flee were struck.

The eventual fate of the entire swath of eastern Syria now under US military control as a result of Daesh war has yet to be decided. Trump’s sudden announcement that the troops would be withdrawn set off an international scramble to figure out what to do with the territory, amounting to almost a third of Syria.

US officials held talks with Turkish officials in Ankara on Friday concerning Turkey’s demand for some form of “safe zone” in northeastern Syria. The Kurds in the US-allied YPG are aligned with the Turkish PKK guerrilla group, and Turkey has said it will deploy troops across the border into Syria to prevent Kurds from launching cross-border attacks once the US troops have gone.

The Kurds, however, fear persecution by the Turks should Turkey assume responsibility and have turned to Russia for help in brokering a deal that would give the Syrian government overall control of the area.

Turkey is also discussing with Russia the possibility of restoring Syrian government control under the terms of a 1998 agreement between Turkey and Syria, which required Damascus to guarantee that Kurds would not launch attacks against Turkey from Syria.

Any vacuum of authority in the area would offer an opportunity for the Islamic State to re-establish itself among the local populace, whose loyalties are deeply divided among the multiple powers competing for control, said Nicholas Heras of the Centre for a New American Security.

“The end of the caliphate is the beginning of the long job of figuring out how to maintain stability in one of the most tribal and restive areas of Syria,” he said. “It will be an uphill climb, and no foreign actor, not the U.S., not Russia, not Iran and not Turkey, will have an easy time of keeping Daesh out for long.”