BAGHOUZ, Syria (AP) — US-backed forces in Syria announced Saturday they have liberated the last pocket of territory held by the Islamic State in Syria, declaring victory over the extremist group and bringing an end to the caliphate it declared in 2014.

The capture of the village of Baghouz in eastern Syria by the Kurdish-led Syrian Democratic Forces brings to a close a grueling battle that stretched across several weeks and saw thousands of people flee the territory and hundreds killed.

“Baghouz is free and the military victory against Daesh has been achieved,” tweeted Mustafa Bali, a spokesman for the SDF, referring to the group by its Arabic acronym.

The elimination of the last IS stronghold in Baghouz marks the end of the militants’ proto-state, which at its height blanketed large parts of Syria and Iraq, but the group maintains a scattered presence and sleeper cells across Syria and Iraq. IS affiliates in Egypt’s Sinai Peninsula, Afghanistan and other countries continue to pose a threat, and the group’s ideology has inspired so-called lone-wolf attacks that had little if any connection to its leadership.

The campaign to take back the territory by the US and its partners has spanned five years and two US presidencies, unleashed more than 100,000 bombs and killed untold numbers of fighters and civilians.

But the weekend announcement, in a tweet, was anti-climactic, and on the ground sporadic gunfire continued. A day earlier, US President Donald Trump declared that Islamic State militants no longer control any territory in Syria.

Associated Press journalists in Baghouz on Saturday reported hearing mortars and gunfire directed toward a cliff overlooking Baghouz, where US-led coalition airstrikes were carried out a day earlier. SDF spokesman Kino Gabriel told the AP Friday that there were IS fighters hiding in caves near Baghouz and that clearing operations were still underway.

On Saturday, journalists were taken to an encampment in Baghouz where the group had made its last stand — a wasteland of wrecked vehicles, torn tents and scorched trees.

Personal belongings and other items including generators, oil barrels, water tanks and satellite dishes were scattered in the dirt. Cars and motorcycles were turned to rusted, twisted heaps of metal. Amid the empty fox holes and trenches stood a building with a huge yellow SDF flag on top.

Ciya Kobani, an SDF commander, announced the end of the operation from the rooftop: “We have been victorious against Daesh,” he declared.

At its height, the Islamic State group ruled a third of both Syria and Iraq, holding millions of people hostage to its harsh and violent interpretation of Islamic law. The group carried out large-scale massacres and documented them with slickly produced videos circulated online. During a rampage through Iraq’s Sinjar region in 2014, it captured thousands of women and girls from the Yazidi religious minority and forced them into sexual slavery. Many remain missing to this day.

The group also used its caliphate as a launchpad for attacks around the globe, including the assaults in Paris in 2015 that killed more than 130 people.

While it imposed an unforgiving version of Islamic law through public beheadings and crucifixions, the group also carried out the mundane duties of governance in its territories, including regulating prices at markets and building infrastructure.