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.

Over the weekend, hundreds of protesters gathered outside the Chinese consulate in Istanbul.
Tourists have been warned to avoid filming protests or going out alone.
China said it has always attached great importance to and fully respects the freedom of Muslim religious beliefs.
A statement from the government said accusations in the Western media that religious rites had been banned in western China's Xinjiang province this Ramadan were "completely at odds with the facts".
Turkish Muslims and Chinese Uighurs share ethnicity and have close cultural and religious ties.
Ankara summoned the Chinese ambassador last week over reports that Beijing had banned Uighurs from fasting and worship during the holy month.
Hundreds have died in violent attacks in Xinjiang in recent years. China blames the violence on Islamist terrorist groups but Uighur groups say the unrest is being fuelled by Beijing's repressive policies.
On Sunday, protesters at the Chinese consulate were pictured burning the Chinese flag and holding banners, one of which said "Turkey save your Brother - China get out from East Turkestan".
China crushed the short-lived state of East Turkestan in 1949. It established the Xinjiang Uyghur Autonomous Region in 1955.
The Chinese foreign ministry said there had recently been "multiple" demonstrations in Turkey targeting the Chinese government and "several" Chinese tourists had been attacked.
Turkish media reported a group of Korean tourists believed to be Chinese were attacked and tear gas was used by police to disperse protesters.
The last year has seen a crackdown in Xinjiang on what China describes as "terrorism driven by religious extremism".
In some places, the government has banned Uighurs from buying knives and women from wearing veils.
Security check points have been set up on roads and near markets and shopping malls.
In previous years, students have told the BBC they have been prohibited from taking part in Ramadan fasts, and government departments have restricted civil servants.
On microblog Weibo, one Chinese user, Dan Duo Duo 35, said: "Our policies towards ethnic minorities are still not good enough? They have less strict requirement for university exams, special prayer rooms in airports, and food labelled with Halal.
"The Han people are the disadvantaged one."
The jihadist group Islamic State (IS) says it targeted Shia Muslims in an attack on a Baghdad shopping centre, which reportedly killed 18 people.
[NEXT_CONCEPT]
China has issued travel advice to its citizens travelling to Turkey after it said several tourists were attacked in protests over the Chinese government's treatment of ethnic Uighur Muslims.