BEIRUT, Lebanon — As pro-government troops drove Islamic State fighters from a central Syrian town over the weekend, the retreating militants killed scores of civilians, dumping some bodies into wells and leaving others in the street, local residents and the Syrian state-run news media said on Monday.

The apparent mass killing is the latest example of the brutal reprisals that have taken place when territory changes hands in Syria’s multisided war, with civilians often bearing the brunt of the pain.

The carnage showed how the Islamic State can still spread havoc even as it loses major parts of its territory that once included large areas of Syria and Iraq.

At least 67 bodies had been identified in the town, Qaryatayn, northeast of Damascus, the capital, by Monday afternoon, according to local activists who posted an online list of the victims’ names.