Militants’ attempts to free inmates at two major prisons in Iraq have left at least 25 members of the security forces dead, while a car bombing targeting soldiers killed another 12, officials said.

Battles raged for up to two hours at both the Taji and Abu Ghraib jails on the outskirts of Baghdad, with suicide bombers in both raids driving cars up to the main gate before blowing themselves up.

Other insurgents detonated bombs and fired mortar rounds in attacks which began late on Sunday. While the fighting ensued outside, rioting prisoners set fire to blankets and furniture.

Download the new Independent Premium app Sharing the full story, not just the headlines

Police did not officially report any successful break-outs, but local media and jihadist internet forums said some prisoners managed to flee. Many of the thousands inside Taji and Abu Ghraib are being held on terrorism charges, and their numbers include members of al-Qa'ida’s Iraq branch.

Officials reported that 15 soldiers died and 13 others were wounded in the attack at Taji, with at least six militants also among the dead.

At Abu Ghraib, 10 policemen were killed and 19 were wounded. At both sites security forces found further supplies of undetonated car bombs and explosive belts in the aftermath of the fighting.

The prisons both used to be operated by the US military but control was handed back to Iraq authorities in advance of the last American withdrawal in December 2011.

Meanwhile, in a separate incident early on Monday, a suicide bomber drove a car full of explosives into an army patrol in northern Iraq, leaving at least 12 people dead.

The patrol was travelling through a residential area in the city of Mosul, 220 miles northwest of Baghdad. Nine soldiers and three civilians were killed, according to reports from a police officer. He added that 14 others, included four civilians, were wounded.

Three medical officials confirmed the casualty figures to the Associated Press.

The number of attacks has escalated since the start of the Islamic holy month of Ramadan on 10 July. More than 450 people have been killed, amid a larger spike in bloodshed in recent months.

There are growing fears of a return to the widespread sectarian killing that pushed the country to the brink of civil war after the 2003 US-led invasion.