Iraqi officials say militants accidentally set off their own car bomb at a training camp north of Baghdad, leaving 21 dead.

A police officer said the militants were attending a lesson on Monday on making car bombs and explosive belts at the camp near the town of Samarra when a glitch set off one of the devices.

The officer said security forces rushed to the area after hearing the explosion and arrested 12 of the wounded, as well as 10 suspected militants who were trying to flee.

Security forces found seven car bombs, several explosive belts and roadside bombs after searching two houses and a garage in the orchard, he said.

Medical officials confirmed the casualties. Car bombs are one of the deadliest weapons used by the al-Qaida breakaway group in Iraq that dominates the Sunni insurgency in Iraq, with coordinated waves of explosions regularly leaving scores dead in Baghdad and elsewhere across the country.

The bombs are sometimes assembled in farm compounds where militants can gather without being spotted, or in car workshops in industrial areas. Police say the camp outside Samarra, a Sunni city 60 miles north of Baghdad, was in an orchard in the village of al-Jalam.

Meanwhile, authorities in the northern city of Mosul said that parliamentary speaker Osama al-Nujaifi escaped an assassination attempt that left one bodyguard wounded.

Police officials said a roadside bomb went off next to the motorcade. Al-Nujaifi was not hurt in the attack.

Violence has increased in Iraq since April 2013. Militant groups regularly stage co-ordinated car bomb attacks in the capital.