At least 12 people were killed and dozens wounded Sunday in an attack by heavily armed militants on an Iraqi military headquarters in the centre of Baghdad.

Iraqi Defence Minister Abdul-Qadir al-Ubaidi, centre, inspects the site of a suicide attack by militants on an Iraqi military headquarters Sunday.Iraqi Defence Minister Abdul-Qadir al-Ubaidi, centre, inspects the site of a suicide attack by militants on an Iraqi military headquarters Sunday. (APTN/Associated Press)Six militants wearing explosive vests and matching track suits and armed with machine-guns and hand grenades pulled up at a checkpoint with an explosives-laden car, according to a senior Iraqi military intelligence official.

The six left the car and started shooting, killing a soldier at the checkpoint, he said. Guards at an observation tower returned fire, killing four militants, while two entered a building in the military compound.

Iraqi soldiers shot and killed a seventh attacker who was driving the vehicle, causing the car bomb to explode, the official said. The blast left behind a gaping crater in the ground.

The fighting came to an end after the two assailants who breached the compound ran out of bullets and detonated their explosive vests, the official said.

It was the first exchange of fire involving U.S. troops in Baghdad since the Aug. 31 deadline for formally ending the combat mission.

The American troops who joined the fight and provided cover fire for Iraqi soldiers pursuing the attackers were based at the compound to train Iraqi forces, said U.S. military spokesman Lt.-Col. Eric Bloom.

Iraqi forces also requested help from U.S. helicopters, drones and explosives experts, he said. No American troops were hurt, Bloom said.