Islamic State launched a surprise attack on Sunday in western Iraq, where the radical militia is under increasing pressure, Iraqi military said.
The extremists targeted the town of Hit, around 110 kilometres west of Baghdad, with heavy shelling and suicide bombings.
“Military units and tribal fighters managed to repulse the attack and killed 40 Daesh elements,” said Ali al-Zawabi of the army Seventh Division based in Hit, using an Arabic acronym for Islamic State.
He told dpa that six government fighters were killed, and eight others, including the police chief in Hit, were injured in ensuing clashes.
However, Amaq, a news agency linked to Islamic State, reported that the group took control of half of the town and killed at least 40 government fighters.
The attack comes as government forces, backed by a US-led air alliance, are pressing ahead with an offensive aimed at driving Islamic State from Fallujah, the radical group’s stronghold in western Iraq.
Hit is strategically located near the Ain al-Assad airbase where US troops are training Iraqi forces.
Government forces retook Hit from Islamic State last month.
In December 2015, Iraqi troops had driven the militants out of Ramadi, the capital city of the western Anbar province.
Islamic State still controls Mosul, Iraq’s second-largest northern city.
Iraqi Kurdish fighters, backed by US-led airstrikes, Sunday retook villages from Islamic State near Mosul, Kurds said.
The reported advance came after Peshmerga Kurdish forces attacked Islamic State positions in the area of Khazer, around 45 kilometres north-east of Mosul.
At least 36 militants, including six would-be suicide bombers, were killed in the offensive, Kurdish military said. No Kurdish casualties were given.
The Peshmerga, the troops of Iraq’s autonomous region of Kurdistan, have in recent months played a key role in dislodging Islamic State from areas that the al-Qaeda splinter group had seized in northern Iraq during a lightning onslaught in 2014.
Sunday's attack was ordered by Kurdistan’s President Massoud Barzani, Aziz Wessi, a Peshmerga commander, said.
"The Peshmerga’s victory in this operation will make Erbil secure from dangers," Wessi told reporters, referring to the capital of Kurdistan.
In recent months, Islamic State has suffered military setbacks and lost ground in Iraq and neighbouring Syria.