Gunmen stormed the al-Jawhara shopping centre in Baghdad al-Jadida on Monday evening, after setting off a car bomb.
When security forces stormed the building, two assailants detonated explosive belts, while two others were shot dead, police sources say.
At the same time, 20 people died when two bombs exploded north of Baghdad.
Security sources said an improvised explosive device was detonated at a tea shop in the town of Muqdadiya, which is some 80km (50 miles) from the capital.
A second device blew up as medics rushed to the scene to treat the wounded.
Later, five civilians were killed when a car bomb exploded in exploded in the south-eastern Baghdad suburb of Nahrawan, police and medics say.
There was no immediate claim of responsibility for the bombings in Muqdadiya and Nahrawan, but IS said in a statement posted online that it was behind the attack on the Baghdad shopping centre, which is located in a predominantly Shia district.
The Sunni Muslim jihadist group, which controls large swathes of northern and western Iraq, said it had targeted "rejectionist heathens" - its derogatory term for Shia.
Seven people, including two policemen, were killed by the car bomb blast at the start of the attack, police and medics told the Reuters news agency.
Another five were shot dead as the militants stormed the building, while six died when two of the assailants detonated their explosive vests, the sources said.
Interior ministry spokesman Brigadier General Saad Maan denied initial reports that people had been held hostage by the militants, according to Reuters.
An interior ministry source meanwhile told the BBC that several attackers might have escaped, contradicting a claim by a police source that four had been arrested.
The jihadist group Islamic State (IS) says it targeted Shia Muslims in an attack on a Baghdad shopping centre, which reportedly killed 18 people.