BEIRUT/ERBIL (Reuters) - Islamic State’s self-proclaimed caliphate was on the verge of final defeat on Friday, with Syrian government forces capturing its last major city on one side of the border and Iraqi forces taking its last substantial town on the other.

Shi'ite Popular Mobilization Forces (PMF) fighters fire a cannon against Islamic State militants in Al-Qaim, Iraq November 3, 2017. REUTERS/Stringer

The losses on either side of the frontier appear to reduce the caliphate that once ruled over millions of people to a single Syrian border town, a village on a bank of the Euphrates in Iraq and some patches of nearby desert.

Officials on both sides of the border said its final defeat could come swiftly, although they still fear it will reconstitute as a guerrilla force, capable of waging attacks without territory to defend.

Iraq’s Prime Minister Haidar Abadi announced that government forces had captured al-Qaim, the border town where the Euphrates spills from Syria into Iraq. That leaves just the village of Rawa further down river on the opposite bank still in the hands of the ultra-hardline militants, who swept through a third of Iraq in 2014.

On the Syrian side, government forces declared victory in Deir al-Zor, the last major city in the country’s eastern desert where the militants still had a presence. Government forces are now about 40 km away from Albu Kamal, the Syrian town across the border from al-Qaim, and preparing for a final confrontation.

A U.S.-led international coalition which has been bombing Islamic State and supporting ground allies on both sides of the frontier said before the fall of al-Qaim that the militant group had just a few thousand fighters left, holed up in the two towns on either side of the border.

“We do expect them now to try to flee, but we are cognisant of that and will do all we can to annihilate IS leaders,” spokesman U.S. Colonel Ryan Dillon said.

“As IS continues to be hunted into these smallest areas ... we see them fleeing into the desert and hiding there in an attempt to devolve back into an insurgent terrorist group,” said Dillon. “The idea of IS and the virtual caliphate, that will not be defeated in the near term. There is still going to be an IS threat.”

The group’s leader, Abu Bakr al-Baghdadi, is believed to be hiding in the desert near the frontier.

BESIEGED IN ALL DIRECTIONS

Driven this year from its two de facto capitals -- Iraq’s Mosul and Syria’s Raqqa -- Islamic State has been squeezed into an ever-shrinking pocket of desert straddling the frontier by enemies that include most regional states and global powers.

In Iraq, it faces the army and Shi’ite armed groups, backed both by the U.S.-led international coalition and by Iran. In Syria, the U.S.-led coalition supports an alliance of Kurdish and Arab militias north and east of the Euphrates, while Iran and Russia support the government of President Bashar al-Assad.

On the Syrian side, Friday’s government victory at Deir al-Zor, on the west bank of the Euphrates, ended a two month battle for control over the city, the center of Syria’s oil production. Islamic State had for years besieged a government enclave there until an army advance relieved it in early September, starting a battle for jihadist-held parts of the city.

“The armed forces, in cooperation with allied forces, liberated the city of Deir al-Zor completely from the clutches of the Daesh terrorist organization,” state media reported, using an Arabic acronym for Islamic State.

Engineering units were searching streets and buildings in Deir al-Zor for mines and booby traps left behind by Islamic State fighters, a Syrian military source told Reuters.

The source added that he did not believe the final battle at the Albu Kamal border town would involve “fierce resistance”, as many fighters had been surrendering elsewhere.

“Some of them will fight until death, but they will not be able to do anything,” he said. “It is besieged from all directions, there are no supplies, a collapse in morale, and therefore all the organization’s elements of strength are finished.”

Once Albu Kamal falls, “Daesh will be an organization that will cease to exist as a leadership structure,” the military source said. “It will be tantamount to a group of scattered individuals, it will no longer be an organization with headquarters, with leadership places, with areas it controls.”

In Iraq, Abadi congratulated his forces for capturing al-Qaim “in record time” only hours after commanders announced they had entered it. Earlier in the day, they seized the border checkpoint on the road to Albu Kamal in Syria.

Iraq’s joint operations command said the only territory left to capture is Rawa, a small village on the opposite bank of the Euphrates.

Iraq has been carrying out its final campaign to crush the Islamic State caliphate while also mounting a military offensive in the north against Kurds who held an independence referendum in September.