BAGHDAD -- An instructor teaching his militant recruits how to make car bombs accidentally set off explosives in his demonstration Monday, killing 21 of them in a huge blast that alerted authorities to the existence of the rural training camp in an orchard north of Baghdad. Nearly two dozen people were arrested, including wounded insurgents trying to hobble away from the scene.

The fatal goof by the al Qaeda breakaway group that dominates the Sunni insurgency in Iraq happened on the same day that the speaker of the Iraqi parliament, a prominent Sunni whom the militants consider a traitor, escaped unhurt from a roadside bomb attack on his motorcade in the northern city of Mosul.

Nevertheless, the events underscored the determination of the insurgents to rebuild and regain the strength they enjoyed in Iraq at the height of the war until U.S.-backed Sunni tribesmen turned against them. The militants are currently battling for control of mainly Sunni areas of western Iraq in a key test of the Shiite-led government's ability to maintain security more than two years after the withdrawal of U.S. troops.

While the Iraqi army has been attacking insurgent training camps in the vast desert of western Anbar province near the Syrian border, it is unusual to find such a camp in the centre of the country, just 95 kilometres (60 miles) north of the capital.

The discovery shows that "the terrorist groups have made a strong comeback in Iraq and that the security problems are far from over, and things are heading from bad to worse," said Hamid al-Mutlaq, a member of the parliament's security and defence committee.

The militants belonged to a network now known as the Islamic State of Iraq and the Levant, an extremist group that recently broke with al Qaeda. The ISIL, emboldened by fellow fighters' gains in the Syrian civil war, has tried to position itself as the champion of Iraqi Sunnis angry at the government over what they see as efforts to marginalize them.

Car bombs are one of the deadliest weapons used by this group, with co-ordinated 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.

The explosion Monday took place at a camp tucked away in an orchard in the village of al-Jalam, a farming area that has been a stronghold of al Qaeda close to the Sunni city of Samarra. According to a police officer, an army official and a hospital official, all of whom spoke on condition of anonymity for security reasons, the events unfolded as follows.

The militants were attending a lesson on making car bombs and explosive belts when a glitch set off one of the devices during the car bomb part of the demonstration. Security forces rushed to the area after hearing the thunderous blast and arrested 12 wounded militants along with another 10 trying to flee.

Authorities searched two houses and a garage in the orchard, finding seven car bombs as well as several explosive belts and roadside bombs. The cars did not have license plates. Bomb experts then started the work of defusing the devices.

Later Monday, a bomb exploded near a cafe in western Baghdad shortly after nightfall, killing three people and wounding 11 others, according to police and medical officials who all spoke on condition of anonymity because they were not authorized to speak to media.

The U.S. strongly condemned the assassination attempt on parliament speaker Osama al-Nujaifi, a roadside bombing that wounded one of his bodyguards.

"Speaker Nujaifi has been a strong partner of the United States' efforts in Iraq and we are grateful that he was unharmed in the attack," State Department deputy spokeswoman Marie Harf said in a statement. "Today's attack exemplifies the danger terrorist groups pose to all Iraqis, and the importance of Iraqi leaders from all communities working together to isolate militant groups from the broader population."

Violence has spiked in Iraq since last April, when security forces cracked down on a Sunni protest camp north of Baghdad in clashes that left 45 dead.

The situation deteriorated significantly in late December, when security forces dismantled a protest camp near the Anbar provincial capital of Ramadi. To defuse the tension, the security forces withdrew from Ramadi and the nearby city of Fallujah. ISIL militants promptly took over parts of Ramadi and the centre of Fallujah.

The Iraqi government and allied tribes launched an offensive on Jan. 26 to wrest control of the cities back from the militants. Sporadic clashes are still continuing around Fallujah and in some parts of Ramadi, with only limited success by security forces.