The Islamic State and Syria (ISIS) group on Saturday freed dozens of men it had seized while searching for people who burned its flag in north Iraq, officials and residents said, Agence France-Presse reported.

An intelligence officer and a local official said that 162 out of 170 men were released after being taken by ISIS from the villages of al-Shajara and Gharib in Kirkuk province, where two of the jihadist group's flags were torched.

Earlier, an intelligence officer said that a total of 170 men were taken from the villages of Al-Shajara and Gharib in Kirkuk province, after two ISIS flags were burned in the area, an account confirmed by other officials from the province.

“Members of the (ISIS) organization who were driving around 30 vehicles took the kidnapped (people) to the center of Hawijah,” a nearby town where they have a court and a prison, the officer said.

A resident of al-Shajara said that women pleaded with the ISIS militants not to harm the men, to which the fighters responded that they would investigate and only punish those responsible for the flag burning in the village.

A resident from Gharib said they took around 90 people from that village, and that the fighters said they were searching for 15 men who burned their flag there.

It is not the first time ISIS has turned to mass detentions as it seeks to quell resistance in the swathes of territory in Iraq that it has overrun since June.

It seized 50 people in Kirkuk province after residents burned one of their positions and flag in September, and 20 more the following week for allegedly forming a resistance group.

Some of those seized by ISIS have been subsequently released.

But the group has also executed thousands of people in areas it controls in Iraq and Syria, sometimes in grisly beheadings it videotapes and posts online.