A suicide bombing against a Shia mosque as worshippers streamed out was the deadliest of attacks across Iraq that left 37 dead on Wednesday, part of a surge in violence.
Dozens were wounded in the bloodshed, and locals exacted a grim revenge on one man suspected of being a second attacker in the mosque bombing, which comes amid Iraq's worst bloodshed since 2008.
Authorities have sought to tackle the unrest with a string of measures ranging from massive security operations targeting militants to implementing tight restrictions on vehicle movement in the capital in a bid to stem the number of car bombs.
But attacks have continued to hit much of the country, with more than 4,000 people killed in violence already this year.
The worst of Wednesday's violence struck the confessionally-mixed north Baghdad neighbourhood of Waziriyah, where a suicide bomber blew himself up at a mosque at around 6:40 pm (1540 GMT) as worshippers were exiting following evening prayers.
At least 30 people were killed and 55 others wounded, an interior ministry official and a police source said, speaking on condition of anonymity.
Immediately after the bombing, locals spotted a man they suspected was about to blow himself up as well, and gunned him down before setting his corpse ablaze, the sources said.
No group immediately claimed responsibility for the attack against the Tamimi mosque, a Shiite place of worship, but Sunni militants linked to Al-Qaeda frequently set off attacks against Iraq's Shiite majority, who they regard as apostates.
Violence elsewhere in the country left seven people killed, including four in the restive northern province of Nineveh.
In three separate attacks in the province, which remains one of Iraq's least stable, gunmen killed three people, among them a school principal who was shot dead at his house.
And in provincial capital Mosul, a magnetic "sticky bomb" attached to a car killed another person.
Another sticky bomb killed one person in south Baghdad, and another died in a roadside bombing in a town on the capital's southern outskirts, while a gunman on a motorcycle killed a Sunni imam near the southern port city of Basra.
The surge in bloodshed has sparked concerns that Iraq is slipping back into the all-out sectarian war that plagued it in 2006 and 2007 leaving tens of thousands dead.
Officials have vowed to press on with a campaign targeting militants they say has led to the capture of hundreds of fighters and the killing of dozens more, as well as the dismantling of militant training camps and bomb-making sites.
But the government has faced criticism for not doing more to defuse anger in the Sunni Arab community over alleged ill-treatment at the hands of the Shiite-led authorities, which analysts and diplomats say militant groups exploit on the ground to recruit and carry out attacks.
This month, an Al-Qaeda front group claimed responsibility for a spate of car bombs in Baghdad that targeted Shiite areas and left 50 dead.
It has explicitly said attacks have been carried out in retribution for operations targeting Sunnis and the executions of convicted militants.