BAGHDAD — A year after it was routed from Iraq in a devastating war that left entire neighborhoods and towns in ruins, the Islamic State group is fighting to hang on to its last enclave in eastern Syria, engaging in deadly battles with U.S.-backed forces.

Cornered in the desert near the Iraqi border with nowhere to run, the militants are putting up a fierce fight, inflicting hundreds of casualties among their opponents and releasing a stream of beheading videos reminiscent of the extremist group’s terrifying propaganda at the height of its power.

In Syria, the battle for the area of Hajin has dragged on for three months, highlighting the difficulty of eradicating an extremist group determined to survive. Across the border, in Iraq, there is rising concern that the group may stage a comeback. IS sleeper cells have recently launched deadly attacks against security forces and abducted and killed civilians, mostly in four northern and central provinces that were once part of the group’s self-declared caliphate.

“There is still major danger for Iraq and Syria especially in areas close to the border when it comes to Daesh,” a senior Iraqi intelligence official said, using an Arabic acronym to refer to the extremists. He spoke on condition of anonymity because he was not authorized to speak to the media about security matters.

He said IS lost most of the income it once made from oil and taxes imposed in areas it controlled. The group now relies on selling gold and other reserves that they had accumulated after declaring their caliphate in June 2014. He said the money is being used to buy weapons and finance attacks in Iraq and Syria.

Another Iraqi intelligence official said IS has begun restructuring its command, relying more on non-Iraqi commanders after most of its leaders were killed in coalition strikes.

The Islamic State group once held an area the size of Britain across vast territories straddling parts of Iraq and Syria, running a so-called caliphate and planning international attacks from its headquarters in the Syrian city of Raqqa. Tens of thousands were killed in both countries as an array of local forces, some backed by a U.S.-led coalition, eventually drove the extremists out of virtually all the lands they once held.

Iraq’s then-Prime Minister Haider al-Abadi declared final victory over the group on Dec. 9, 2017. Two months earlier, the coalition, working with Kurdish-dominated fighters known as the Syrian Democratic Forces, liberated Raqqa after a bombing campaign that decimated much of the city.

The area that IS still holds in Syria represents less than 1 percent of the territory it controlled at its height. The pocket is home to some 15,000 people, including IS fighters and their families. The U.S. military estimates there are about 2,000 remaining IS fighters there.

The fighting is now believed to be in its final stages, with SDF fighters said to have broken IS defenses and taken the fight inside the town.