Cornered in Baghuz, Syria, the last 1.5-square-mile remnant of the group’s original caliphate in the region, the remaining militants waged a surprisingly fierce defense and kept the American-backed forces at bay for months.

They detonated car bombs and hurled explosives from drones. Suicide bombers ran across the front line under cover of darkness to attack the sleeping quarters of the American-backed coalition.

In the last weeks, the militants’ families fled for their lives, their black-clad wives streaming into the desert by the tens of thousands, some of them defiantly chanting Islamic State slogans and lobbing fistfuls of dirt at reporters.

But after a grueling campaign, the last speck of land was finally wrested from the Islamic State, also known as ISIS.

“This is a big moment not just for us but for all of the world,” said Kino Gabriel, a spokesman for the Syrian Democratic Forces, the American-backed militia that led the operation. “But we cannot say that ISIS is finished. It is true that they are finished on the ground as a standing army. But the ISIS threat remains around the globe.”

At its zenith four years ago, the Islamic State ruled a chunk of territory the size of Britain and controlled the lives of up to 12 million people.

It captured major population centers, including Mosul, the second largest city in Iraq. Its dominion extended east into the plains of Nineveh in Iraq, an area mentioned in the Bible where the group used the walls of ancient churches for target practice. It reached south to the Syrian ruins of Palmyra, whose majestic pillars became a backdrop for gruesome beheading videos.

In between, it seized land that accounted for 75 percent of Syria’s cotton crop, 40 percent of Iraq’s wheat production and over 50 percent of its barley fields, as well as hydroelectric dams, phosphate mines and oil fields.

A coalition vehicle drives on Feb. 10 toward the front lines in the battle for Baghuz, the last territory held by ISIS.CreditIvor Prickett for The New York Times
Men who fled the last village held by the Islamic State wait to be questioned by coalition forces in Deir al-Zour Province.CreditIvor Prickett for The New York Times

While the Islamic State lives on as a diffuse insurgency that commands thousands of followers from Afghanistan to the Philippines, the loss of the biggest territory it controlled is a blow. The group lost the most visible prototype of what it envisioned as a global caliphate, a gleaming beacon that helped recruit tens of thousands of fighters from around the world and an ominous nightmare that frightened the rest.

Its vast territory allowed it to do something no other terrorist group had done: By taxing the millions under their rule and exploiting the area’s natural resources, the Islamic State raked in billions of dollars, becoming the world’s richest terrorist organization.

It used that wealth to finance its global ambitions. The militants built a war machine, including industrial-scale mortar production and a drone program that modified off-the-shelf technology to carry explosives, changing the dynamic of a conflict where previously mortars had to be bought on the black market and the American-backed coalition controlled the air.

It invested in its nascent state, providing services like vaccination drives and trash collection that at times rivaled those of the governments they had usurped, one of the selling points it used to lure new recruits.

The cities and towns it held allowed the group to embed prisons, training camps and administrative offices in civilian population centers, protecting them from airstrikes under international norms of warfare.

The state it built, ostensibly modeled on the one established by the Prophet Muhammad in the seventh century, was both brutal and bureaucratically efficient. Women flogged for showing so much as their eyes were issued receipts by the morality police. Teenage boys imprisoned for the crime of “making fun during prayer” were served with arrest warrants. Thousands of women belonging to the Yazidi faith, which the Islamic State considers heretical, were sold into sexual servitude, their rape endorsed by an Islamic court with a stamped contract.

Women and children fleeing the last area controlled by ISIS jam into a bus to reach camps controlled by Kurdish Syrian militias.CreditIvor Prickett for The New York Times
A convoy of trucks carrying people away from the last territory held by ISIS in eastern Syria.CreditIvor Prickett for The New York Times

By nearly every metric, the Islamic State, also known as ISIS, is now a diminished force compared to its height four years ago: It has far fewer fighters and far less land, and the number of attacks it carries out worldwide has nose-dived.

And by all accounts, life in Baghuz as it was besieged these last few weeks was bleak.

“Ask me, when is the last time I had an egg? One year ago,” said Amy, a 34-year-old Canadian woman who fled the village recently and gave only her first name. She had left her job as a graphic designer in Alberta with her two toddlers to join her husband inside the caliphate. “I just want to go home and have the biggest Tim Hortons coffee,” she said, referring to the Canadian coffee shop chain.

But those who have tracked the group since it took root in Iraq in the early 2000s point out that even after losing its land, the group is far stronger today than it was the last time it was considered defeated — in 2011, the year American troops pulled out of Iraq.

The militants were down to their last 700 fighters then. Now, American and Iraqi officials estimate that the group still has thousands of fighters and tens of thousands of adherents, dispersed across Iraq and Syria.

Signs of the group’s resurgence are already visible.

In the first 10 months since Iraq’s prime minister at the time, Haider al-Abadi, declared victory over the militants in neighboring Iraq, the group carried out 1,271 attacks there, according to Michael Knights of the Washington Institute for Near East Policy.

Abdulrahman Salam aids his injured father, Salam Abid, at a screening point for those fleeing the last village controlled by ISIS. They said 20 members of their family had been killed by a coalition airstrike.CreditIvor Prickett for The New York Times
An injured woman waiting for a bus to a holding camp in territory controlled by Syrian Kurds.CreditIvor Prickett for The New York Times

In the weeks since President Trump claimed victory over the Islamic State in December, the militants have claimed at least 182 attacks in Syria, killing and wounding 620 people, according to Charlie Winter, a senior research fellow of the International Center for the Study of Radicalization at King’s College London.

“There is a tendency to rush into declarations of victory too fast and too early with jihadist groups,” Mr. Winter said. “It may be weaker in the immediate term, but there is not a chance in hell that it has been defeated.”

Even the commanders who helped free Baghuz caution that this is simply the end of one phase of the conflict and the start of another.

Liberating the cities and towns held by the Islamic State was the easy part, said Adnan Afrin, a commander with the American-backed Syrian Democratic Forces. “When we go to the front lines, we face them,” he said. “We shoot them, they shoot back. We know who is in front of us.”

“But behind us are sleeper cells,” he added. “The fight against the enemy you cannot see is much harder.”

While many may describe the fall of Baghuz as the end of the caliphate, the group’s project was always global, with nearly half of its “provinces” overseas. Even as the territory it holds in Iraq and Syria has reached zero, the group’s franchises abroad are growing, experts say.

In January, back-to-back detonations claimed by the Islamic State’s local affiliate killed at least 20 people in the Philippines. In Afghanistan, the group continues to mount deadly attacks, despite the United States’ dropping, in 2017, what it called the “mother of all bombs” on a cave complex used by the militants.