The Islamic State group launched attacks on Iraqi bases in two western towns that left at least 17 members of the security forces and 40 jihadists dead, security and medical sources said Thursday.

Seven policemen and four soldiers were killed when IS fighters attacked the police headquarters in the town of Heet, while at least six members of federal forces were killed in an assault on a major army base in Ramadi.

In Heet, a town on the Euphrates about 150 kilometers (95 miles) west of Baghdad, 25 gunmen attacked the police headquarters shortly after midnight.

"They smashed the gates open with suicide car bombs, the 25 men tried to break into the HQ, sparking heavy clashes," police colonel Jabbar al-Nimrawi told AFP.

"The police killed 20 of them and the remaining five withdrew to the electricity building. They are still under siege, they have sniper rifles," he said.

Nimrawi said the building was now surrounded by police, army, counter-terrorism elite troops and anti-jihadist Sunni tribal forces.

Doctor Nael Ahmed, from Heet hospital, said seven police officers and four soldiers were killed in the attack and the ensuing clashes.

In Ramadi, less than 100 kilometers (60 miles) west of Baghdad, further down the Euphrates river, a similar suicide unit attacked the 8th Brigade headquarters, just outside the city, on Wednesday.

"They attacked from three directions. They used suicide armored vehicles to break into the compound, then 13 fighters with suicide vests entered," said senior army officer Awad al-Dulaimi.

"We killed the last one at 5:00 am (0200 GMT) after fierce exchanges. We also killed seven who had come from another direction," he said.

A doctor at Ramadi hospital, Ahmed al-Ani, confirmed that he had received the bodies of three members of Iraq's elite counter-terrorism force, including a colonel, and three soldiers.

Some of the last pockets still under government control in the Sunni province of Anbar are in Heet in Ramadi.