American soldiers helped Iraqi troops battle insurgents in downtown Baghdad on Sunday, repelling a major attack in the heart of the capital five days after President Obama declared an end to U.S. combat operations.

At least 18 people were killed and 39 injured in the midday attack in which a group of suicide bombers and gunmen attempted to storm the Iraqi army’s east Baghdad headquarters, located in a former Ministry of Defense building in a busy market district alongside the Tigris River.

No Americans were among the casualties, said military spokesman Lt. Col. Eric Bloom. But U.S. soldiers did join in the fighting alongside Iraqis to repel the assailants, two of whom managed to enter the army compound.

“Soldiers living and working at Old MoD provided suppressive fire while IA [Iraqi army] soldiers located the two terrorists that entered the compound,” he said in an e-mail. The firefight lasted “a few minutes,” he said.

The U.S. military also dispatched helicopters, bomb disposal experts, unmanned aerial drones and other unspecified “intelligence, surveillance and reconnaissance” assets to the scene of the downtown battle, he said, highlighting the continued dependence of the Iraqi security forces on American expertise and high-tech equipment.

An official with the Interior Ministry, speaking on condition of anonymity, said that the Iraqi security forces requested American help to defeat the insurgents, and that it was U.S. soldiers who shot two snipers who had taken up position in nearby buildings.

It was the first significant attack in Baghdad since Obama’s address to the nation Tuesday in which he told Americans that U.S. combat operations were over and said it was now time to “turn the page” on Iraq.

The last official American combat brigade withdrew from Iraq in August, leaving behind 50,000 troops attached to what are called “advise and assist brigades.” The six brigades are made up of combat soldiers whose mission is to offer advice and assistance to the Iraqi army. In addition, about 4,500 Special Forces soldiers still conduct regular combat operations alongside Iraqi counter-terrorism forces.

But as Sunday’s attack illustrated, there is still a very real danger that regular U.S. soldiers traveling with Iraqi army units will get caught up in fighting.

The soldiers who joined the battle were assigned to one of dozens of Stability Transition Teams, made up of military experts who live with Iraqi army units along with a company of American soldiers for protection. Bloom did not say how many U.S. soldiers were at the base, but a typical team numbers about 70.

The attack began when a suicide bomber detonated an explosives-packed minivan outside the gates of the Iraqi headquarters. Four or five more suicide bombers then attempted to storm the compound, triggering a 15-minute gun battle. But it appeared to have taken longer to hunt down the last assailants; witnesses said sporadic shooting continued for several hours.

Shoppers fled, stores shuttered and the Iraqi security forces sealed off the area for several hours, paralyzing the commercial heart of the city. Helicopters hovered overhead and smoke billowed from the site of the initial explosion.

Five Iraqi soldiers, seven civilians and six insurgents were killed, and one insurgent was injured and detained, police said.

It has become rare for U.S. soldiers to get involved in combat operations, and this is believed to be the first time that regular American ground forces have fought inside Baghdad since the June 2009 deadline for their withdrawal from Iraq’s cities. Under the terms of the U.S. security agreement with Iraq, American soldiers no longer have the right to conduct unilateral combat operations in Iraqi cities without being asked by the Iraqi authorities.

More such incidents may occur in the future. Insurgents have been stepping up their attacks against Iraqi security forces in recent weeks in an apparent attempt to undermine the army and police as U.S. forces reduce their role. Sunday’s attack occurred at the scene of a suicide bombing on Aug. 17 that killed at least 48 army applicants.

It also echoed a June attack in the same area in which multiple suicide bombers stormed the Central Bank, suggesting that Iraqi security forces still have not managed to secure the heart of the capital against insurgents.

liz.sly@latimes.com

Mohammed is a Times staff writer.