The attack came in the northern Hurriyah district, adjacent to areas swept recently by the US military Operation Together Forward but not yet entered itself.
Ahead of the attacks a previously unknown group calling itself Brigade of Two Sadrs Shula threw leaflets in the streets threatening to kill 10 Sunnis for every Shia death in Baghdad.
In the morning attack, about 20 gunmen entered Hurriyah in five cars, attacked several houses and set fire to two.
They then opened fire on two mosques, damaging the buildings but not causing any injuries.
When US and Iraqi soldiers arrived, supported by helicopters, the gunmen fled.
In a separate incident, police found the bodies of nine men from the al-Duleimi Sunni tribe, blindfolded with their hands and legs bound.
The group of relatives had been dragged out of a wedding dinner in east Baghdad on Thursday night by men dressed in Iraqi army uniforms.
Seven other bodies were found in the capital on Friday police said.
US forces needed
Jalal Talabani, Iraq’s president, addressed the UN General Assembly in New York on Friday.
Talabani said that terrorist operations are not only killing innocent people and creating security chaos, but aim to destroy efforts to rebuild the country and put it “on the path of peace, security and democracy”.
He said US forces needed to stay until Iraqi forces are capable of ending terrorism and maintaining security.
Talabani said: “We must emphasise that the forces of extremism, those who oppose democracy and humanitarian values are intent on making Iraq a stepping stone for reaching other goals, for even more destruction.
“They are composed of regional and Arab elements that export their crises… and fight their battles on Iraq’s territory and among the people of my country.”
A US commander has said the Iraqi government has been unable to produce 3,000 army troops that were promised for security operations in Baghdad because they do not want to leave their regions.
Major General James Thurman, the commander of US forces in Baghdad, said he needed the troops to reinforce US troops and police in areas of the city that are being cleared of fighters.
Thurman said: “Some of these battalions, when they were formed, were formed regionally, and some of the soldiers, due to the distance, did not want to travel into Baghdad. And the minister of defence is working with that.”
The Iraqi government promised the battalions as part of the Operation Together Forward campaign launched in August to quell sectarian violence in the city.