Officials said the toll could rise since many of the dead had been reduced to scattered body parts and not been fully counted.
After dark, there was sporadic gunfire in several districts.
One of the blasts went off at a market, a regular target for Sunni fighters in the sectarian conflict that has killed thousands of people in Iraq. The neighbourhood is a stronghold of the Shia cleric Muqtada al-Sadr.
After the attacks, Nuri al-Maliki, the Iraqi prime minister, warned of “the dark hand of conspiracy that is shedding the blood of the innocent” and urged restraint, saying those responsible would be caught.
Leading Shia, Sunni and Kurdish politicians made a joint appeal for calm on Iraqi television.
Interior ministry sources said five people were wounded at the health ministry building, about 5km from Sadr City.
“The gunmen came in civilian cars and pick-up trucks and started shooting at the building”
Hakim al-Zamili, deputy health minister
Send us your views
The attackers fired mortars, rocket-propelled grenades and machine guns into the compound. The ministry is run by followers of al-Sadr.
Hakim al-Zamili, the deputy health minister, was trapped in the building with the employees.
He said: “First, a series of mortars were fired at the building from the nearby Al-Fadhel neighbourhood, and then about 100 masked gunmen holding machine guns attacked.
“The gunmen came in civilian cars and pick-up trucks and started shooting at the building and wounded a number of employees.”
The attackers later withdrew after clashes with American and Iraqi security forces.
A health ministry spokesman said: “The gunmen fled as American helicopters and Iraqi armoured vehicles arrived. Employees were [later] able to leave.”
The fighting lasted for several hours but the attackers failed to break into the ministry compound.