Members of the Syrian Democratic Forces (SDF), trained by the US-led coalition, participate in the graduation ceremony of their first regiment in al-Kasrah, in the suburb of eastern Syrian city of Deir Ezzor, on May 21, 2018.

U.S.-backed forces declared military victory over the Islamic State group in Syria on Saturday after liberating the last pocket of territory held by the militants in the country's east, marking the end of a brutal self-styled caliphate the group carved out in large parts of Iraq and Syria in 2014.

After weeks of heavy fighting, the tent camp where the militants made their final stand in the village of Baghouz was bombed to shreds. All that remains is a field pitted by abandoned trenches and bomb craters, littered with scorched tents and the twisted metal carcasses of vehicles. Half buried in the dirt was a tattered shred of IS's notorious black flag.

"Baghouz is free and the military victory against Daesh has been achieved," tweeted Mustafa Bali, a spokesman for the Kurdish-led Syrian Democratic Forces, referring to the group by its Arabic acronym.

The elimination of the last IS stronghold in Baghouz brings to a close a grueling final battle that stretched across several weeks and saw thousands of people flee the territory and surrender in desperation, and hundreds killed.

It spells the end of the militants' proto-state, which at its height four years ago was the size of Britain and home to some 8 million people, but the extremist group still maintains a scattered presence and sleeper cells across Syria and Iraq. It's not known whether the group's leader, Abu Bakr al-Baghdadi, is still alive or where he might be hiding.

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 U.S. and its partners has spanned five years and two U.S. 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, 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 U.S.-led coalition airstrikes were carried out a day earlier. SDF spokesman Kino Gabriel said 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. A faint smell of rotting corpses hung in the air.

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. There were unused rockets, mortars and grenades, as well as a pile of suicide vests. 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.