BAGHDAD—Days after the U.S. officially ended combat operations and touted Iraq's ability to defend itself, American troops found themselves battling heavily armed militants assaulting an Iraqi military headquarters in the center of Baghdad on Sunday. The fighting killed 12 people and wounded dozens.

It was the first exchange of fire involving U.S. troops in Baghdad since the Aug. 31 deadline for formally ending the combat mission, and it showed that American troops remaining in the country are still being drawn into the fighting.

The attack also made plain the kind of lapses in security that have left Iraqis wary of the U.S. drawdown and distrustful of the ability of Iraqi forces now taking up ultimate responsibility for protecting the country.

Sunday's hour-long assault was the second in as many weeks on the facility, the headquarters for the Iraqi Army's 11th Division, pointing to the failure of Iraqi forces to plug even the most obvious holes in their security.

Two of the four attackers even managed to fight their way inside the compound and were only killed after running out of ammunition and detonating explosives belts they were wearing.

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.

Under an agreement between the two countries, Iraq can still call on American forces to assist in combat and U.S. troops can defend themselves if attacked.

In Sunday's assault, six militants wearing explosives vests and matching track suits and armed with machine guns and hand grenades pulled up at a checkpoint with an explosives-laden car, said a senior Iraqi military intelligence official who was inside the building at the time.

The six assailants 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 explosives vests, the official said. He spoke on condition of anonymity because he was not authorized to speak to reporters.

Two weeks earlier, an al-Qaida-linked suicide bomber waded into a crowd of hundreds of army recruits outside the building and detonated a blast that killed 61 people. That was the deadliest act of violence in Baghdad in months.

There was no immediate claim of responsibility for Sunday's attack.

Baghdad has been on high alert since President Barack Obama declared the official end to U.S. combat operations on Wednesday, setting up more checkpoints, intensifying searches of people and vehicles and handing out more guns and bullets to troops guarding the capital.

The number of U.S. troops has fallen from a high of 170,000 to just under 50,000 this August; all U.S. troops must be out of Iraq by 2012.

The remaining American soldiers have a noncombat role and mostly assist Iraqis in stabilizing the country. However, U.S. forces can still help Iraqi forces hunt down al-Qaida and other militants and can defend themselves or their bases against attacks.

Insurgents have intensified their strikes on Iraqi police and soldiers to mark the change in the U.S. mission.

Iraq's political instability now appears to be threatening the country's security. Six months after an inconclusive election, Iraq still has no new government. Prime Minister Nouri al-Maliki, a Shiite, is struggling to keep his job after his political coalition came in a close second to a Sunni-backed alliance in the March 7 vote.

------

Associated Press writers Qassim Abdul-Zahra, Rebecca Santana and Hamid Ahmed contributed to this report.

© Copyright 2010 Associated Press. All rights reserved. This material may not be published, broadcast, rewritten, or redistributed.