The "caliphate" declared by ISIL in 2014 was on Friday reduced to little more than a pair of border towns at the Iraq-Syria frontier, where thousands of fighters are believed to be holding out after losing nearly all other territory in both countries.
On the Syrian side, government forces declared victory in Deir Ezzor, the last major city in the country's eastern desert where the militants still had a presence. On the Iraqi side, pro-government forces said they had captured the last ISIL-held border post with Syria in the Euphrates valley and entered the nearby town of Al Qaim, the group's last Iraqi bastion.
Forces in Syria and Iraq backed by regional states and global powers now appear on the cusp of victory over the group, which proclaimed its authority over all Muslims in 2014 when it held about a third of both countries and imposed its brutal rule over millions.
A US-led international coalition which has been bombing ISIL and supporting ground allies on both sides of the frontier said the militant group now had a few thousand fighters left, mainly holed up at the border in Iraq's Al Qaim and its sister town of Albu Kamal on the Syrian side.
"We do expect them now to try to flee, but we are cognisant of that and will do all we can to annihilate ISIL leaders," the coalition spokesman US Col Ryan Dillon said.
He estimated there were 1,500-2,500 fighters left in Al Qaim and 2,000-3,000 in Albu Kamal.
But both the Iraqi and Syrian governments and their international backers say they worry that the fighters will still be able to mount guerrilla attacks once they no longer have territory to defend.
"As ISIL 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," Col Dillon said. "The idea of ISIL and the virtual caliphate, that will not be defeated in the near term. There is still going to be an ISIL threat."
Driven this year from its two de facto capitals - Mosul in Iraq and Raqqa in Syria - ISIL has been pressed into an ever-shrinking pocket of desert straddling the frontier.
In Iraq, it faces the army, backed by the US-led international coalition, and Shiite militias backed by the Iraqi government and Iran. In Syria, the coalition supports an alliance of Kurdish and Arab militias in areas north and east of the Euphrates, while Iran and Russia support the government of president Bashar Al Assad.
On the Syrian side, the government victory at Deir Ezzor, on the west bank of the Euphrates, ends a two-month battle for control over the city, the centre of Syria's oil production. ISIL had for years besieged a government enclave there until an army advance relieved it in early September, starting a battle for extremist-held parts of the city.
"The armed forces, in cooperation with allied forces, liberated the city of Deir Ezzor completely from the clutches of the Daesh terrorist organisation," state media reported.
Engineering units were searching streets and buildings in Deir Ezzor for mines and booby traps left behind by ISIL fighters, a Syrian military source said.
Government forces are still about 40km from the border at Albu Kamal, where they are preparing for a final showdown.
"The defeat of Albu Kamal practically means Daesh will be an organisation 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 organisation with headquarters, with leadership places, with areas it controls."
The source added that he did not believe the final battle at Albu Kamal 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 organisation's elements of strength are finished."
In Iraq, the military's Joint Operations Command said on Friday that the army, along with Sunni tribal fighters and Iran-backed Shiite paramilitaries known as Popular Mobilisation Forces, had captured the main border crossing on the highway between Al Qaim and Albu Kamal.
They had also entered the town of Al Qaim itself, which is located just inside the border on the south side of the Euphrates. The offensive is aimed at capturing Al Qaim and another smaller town further down the Euphrates on the north bank, Rawa.
Iraq has been carrying out its final campaign to crush ISIL while also mounting a military offensive in the north against Kurds who held an independence referendum in September.