Two rockets crashed into the outer wall of the Iranian consulate early on Tuesday while a third hit a police vehicle guarding the building.
There were no casualties.
Police said they then foiled another attack on the compound, finding and defusing two rockets.
Iranian state television said the consulate was attacked by four mortar bombs, but that only a car was damaged.
It said two shells landed inside the consulate's grounds while two others hit its walls.
Also early on Tuesday, several mortar shells were fired at the large palace complex that houses the British consulate, a British army base, a UN office and several other organisations.
Only one actually hit the compound.
British military spokesman Major Charles Burbridge said: "These attacks happen from time to time."
In a separate development, British soldiers killed a suspected terrorist during an overnight gun battle in Basra in which a British soldier was wounded.
Burbridge said two platoons conducting a routine patrol received information on "the location of what they believed to be a leading terrorist".
He said as they moved towards the area, they came under fire from a building, and one British soldier was wounded in the ensuing firefight.
The British soldiers killed one man inside the building.
Burbridge said the man was suspected of involvement in executions in Basra and to have been "linked to quite nasty criminal activity".
In a separate development, a car bomb exploded near a petrol station in the Hay al-Amil district in western Baghdad, killing two civilians and wounding another 25.
Elsewhere, assailants killed Mayor Faris Egab of Udhaym town in a drive-by shooting, police said.
In central Baquba, armed men opened fire on a police patrol near the city's prison, killing a policeman and wounding three others, the office said.
Two US soldiers were killed within a half hour of each other in separate incidents in Baghdad, the US military reported on Tuesday.
One soldier was killed when his vehicle struck a roadside bomb in northeast Baghdad while a second was killed by small arms fire shortly thereafter in north-central Baghdad, both on Sunday.