BAGHDAD — Along two sharp curves of the Euphrates River in northeastern Syria, the Islamic State is fighting to hold on to the last speck of the vast territory it once controlled.

At its height, the group enforced its brutal version of Islamic rule over more than 60,000 square miles in Syria and Iraq. It is now squeezed into two villages occupying six square miles. There, its foot soldiers have been engaged in heavy clashes with the American-backed and Kurdish-led militia Syrian Democratic Forces who are battling to take back the turf, according to a spokesman for the militia and observers in the area.

While some of the extremists are fighting to the end, local officials say the militants have been surrendering by the dozens, repeating a pattern observed in other cities shortly before the group was overrun.

Even with the end of the group’s self-proclaimed caliphate in Syria and Iraq within view, Western officials caution that this is not the end of the violent threat posed by the group. It has continued carrying out devastating attacks as it reverts to its insurgent roots, including a suicide bombing that killed four Americans in Manbij last week.