They said the protest by hundreds of residents in Rutbah, in Anbar province, was triggered by the execution earlier on Saturday of Munir al-Kobeisi, a civil servant, for killing a member of the extremist group. The killing was part of a long-running blood feud between two local clans.
Eid Amash, a spokesman for Anbar's provincial government, confirmed al-Kobeisi's execution and the subsequent protest. Officials said they did not know the whereabouts of the detained residents.
Five officers were killed in the attack, which bore the hallmarks of the Islamic State group, whose militants are active in the area near the Jordanian and Syrian borders in western Iraq.
The officials also said a pair of roadside bombs killed five people and injured 19 south and west of Baghdad on Saturday. Also in the capital, assailants using pistols fitted with silencers killed two people in the Jihad neighborhood in western Baghdad before they fled in a car. Other details were not immediately available.