Men in two cars fired at the Rassulluallah mosque early on Saturday, shattering windows and damaging walls, police said.
An hour later, the Ashra al-Mubashara mosque was stormed, but the attackers fled when Iraqi police arrived, officials said.
Sectarian violence has escalated in recent months, killing thousands and forcing many families to flee.
The four US marines died on Thursday during action in al-Anbar province.
More than 2,570 US soldiers have been killed in Iraq since the US-led invasion of the country in March 2003.
Also on Saturday, six labourers were wounded when a bomb hidden in a bag exploded in Baghdad as they gathered in Tayaran Square waiting for work.