A suicide bomber killed 15 people as they left a Shi'ite mosque in the Iraqi capital on Friday and a separate attack on Sunni protesters killed seven, police and medics said.
In Baghdad's northwestern district of Graiaat, witnesses said guards at the exit to the Shi'ite mosque stopped a woman who then blew herself up amidst worshippers leaving after sunset prayers. Suicide bombings are the hallmark of al Qaeda.
The attack on the Sunni protesters took place in Samarra, 100 km (60 miles) north of Baghdad, one of several cities where Sunnis have been protesting against Iraq's Shi'ite-led government since December.
Many Sunnis resent Shi'ite domination since the U.S.-led invasion that toppled Saddam Hussein in 2003 and empowered majority Shi'ites through the ballot box. That was followed by an insurgency that brought Iraq to the brink of civil war.
Protest organiser Adnan Al-Muhanna called on Sunnis to take to the streets daily and follow the example of Egyptians.
Egypt's first freely elected president Mohamed Mursi was toppled on Wednesday after the army intervened following mass demonstrations against his rule, a year after the Islamist was sworn into office.
"Demonstrations can make the change. Neither elections nor weapons can do that," Muhanna said. "Within one year, the Egyptians changed the Mursi regime through demonstrations because they were well-organized."
Protest organisers in Samarra blamed Shi'ite militia for the bombing and said security forces were complicit as the explosives-packed vehicle had passed through several checkpoints.
Protesters' demands range from amending laws they say are used unfairly to persecute Sunnis to carving out their own region akin to Iraq's ethnic Kurds, who run their own administration in the north of the country.
Others want to tear up the constitution altogether, and Sunni insurgents, including Iraq's al Qaeda affiliate, have called on protesters to take up arms against the government of Shi'ite Prime Minister Nuri al-Maliki.
"This explosion was an unsuccessful attempt to stop us demanding our rights, but we will not stop until our demands are met," said protest spokesman Shiekh Mohammed Taha al-Hamdoon.
A surge of violence in Iraq has increased fears of wider conflict in a country where ethnic Kurds, Shi'ite and Sunni Muslims have yet to find a stable power-sharing compromise.
Tensions have been inflamed by the civil war in neighbouring Syria, which is increasingly being fought along sectarian lines and drawing in Shi'ite and Sunni fighters from Iraq and elsewhere to fight on opposite sides.
The number of people killed in militant attacks across Iraq in June reached 761, still well below the height of sectarian bloodletting in 2006-2007, when the monthly death toll sometimes topped 3,000.