The attack on the village of Rashad last month was unusual in recent Iraqi times for its cruelty.

Islamic State gunmen opened fire on a group of seven young men — four cousins, three friends — as they smoked nargilah pipes on a warm evening, residents of the mostly Shiite Muslim village said. Then the militants waited in the dark until a rescue party arrived and turned the guns on them too.

Within hours, Shiite tribesmen had crossed the stream that separates Rashad from its Sunni Muslim neighbors and were going house to house. Families cowered in the foliage. An old man was shot in his bed. By midnight, at least nine more villagers were dead, and the sky burned red as fires ate up their homes.

The initial attack claimed by Sunni extremists of the Islamic State group and the reprisal it provoked underscores how fragile Iraq’s peace remains in some areas four years after the militants’ caliphate was ousted and highlights their enduring potential to stir sectarian violence.

A member of Iraq’s U.S.-trained counterterrorism force said that a similar recent attack in the same province, Diyala, had left five people dead. “ISIS doesn‘t use car bombs there now,” he said, speaking on the condition of anonymity because he was not authorized to talk with the media. “Instead they have snipers and night-vision goggles.”

Jihadist groups such as the Islamic State have historically been active in Diyala, where they’ve tried to capitalize on the grievances of Sunni communities that feel politically marginalized and taken advantage of rugged terrain offering protection from counterinsurgency operations.