The coordinated attacks on the prisons of Taji, north of Baghdad, and Abu Ghraib, west of the Iraqi capital, were launched yesterday night and lasted for around 10 hours, they said.
A police colonel said seven inmates escaped from Abu Ghraib during the clashes, although Islamists claimed on the Internet that thousands of prisoners were freed.
Officials said at least five members of the security forces were killed at Taji prison, and seven others at Abu Ghraib, notorious for abuses committed by US forces against Iraqi detainees in 2004.
It was not immediately known how many of the assailants were killed, wounded or captured.
The attacks were launched at around 9:30 pm (1830 GMT) yesterday when the gunmen fired mortar shells at the prisons.
Explosives on board cars were then detonated near the entrances to the jails, while three suicide bombers attacked Taji prison, said the police colonel.
Fighting continued throughout the night as the military deployed helicopters and sent in reinforcements around the two facilities.
The situation was eventually brought under control by dawn, according to the colonel.
"The security forces in the Baghdad Operations Command, with the assistance of military aircraft, managed to foil an armed attack launched by unknown gunmen against the ... Two prisons of Taji and Abu Ghraib," the interior ministry said in a statement late yesterday night.
But commenters on microblogging website Twitter, including some accounts apparently operated by jihadists, claimed thousands of prisoners had escaped.
The attacks on the prisons came a year after Al-Qaeda's Iraqi front group announced it would target the Iraqi justice system.
"The first priority in this is releasing Muslim prisoners everywhere, and chasing and eliminating judges and investigators and their guards," said an audio message attributed to the group's leader, Abu Bakr al-Baghdadi, in July last year.
