Updated

BAGHDAD -- An Iraqi soldier sprayed gunfire at American troops guarding one of their commanders as he visited an Iraqi military base on Tuesday and killed two of them, the first U.S. servicemen to die since President Barack Obama declared an official end to combat operations in the country last week.

Even after the U.S. dramatically reduced the number of troops and rebranded its mission in Iraq, the attack was a reminder that Americans still have to defend themselves in a dangerous country where Iraqi forces only have a tenuous hold on security. Nine Americans were wounded in Tuesday's shooting.

The attack also showed that even within the walls of U.S. and Iraqi military bases, American soldiers can still be drawn into fighting.

The American commander was meeting with Iraqi military personnel at the base near the city of Tuz Khormato, about 130 miles north of Baghdad.

The assailant opened fire after an argument and was killed in the shootout that followed, said the city's police chief, Col. Hussein Rashid. He did not provide details on the nature of the argument.

"This is a tragic and cowardly act and is certainly not reflective of the Iraqi security forces," said Maj. Gen. Tony Cucolo, the American commander in charge of U.S. forces in northern Iraq.

The U.S. military is investigating, and the soldiers' names were being withheld until their families were notified.

The deaths raise to at least 4,418 the number of U.S. military personnel killed in Iraq since the war began in March 2003, according to an Associated Press count.

The American military has reduced its footprint in Iraq from a one-time high of 170,000 troops to just under 50,000 troops as of Aug. 31.

The remaining troops are tasked with training the Iraqi security forces, providing security for some State Department missions and assisting the Iraqi forces in hunting down insurgent groups.

But U.S. troops are still able to defend themselves and their bases and still come under attack.

On Sunday, American troops in eastern Baghdad helped Iraqi forces repel an assault on an Iraqi military headquarters in what was the first exchange of gunfire involving Americans since the August deadline.

In a statement posted on a militant website, the Islamic State of Iraq took responsibility for the hour-long assault Sunday on the headquarters of the Iraqi Army's 11th Division. It was the second assault on the complex in less than a month and showed the challenges Iraqi security forces are facing after the U.S. change of mission