A suicide bomber struck a Shiite mosque in the Afghan capital on Monday, killing 32 people, the U.N. office said, the second large-scale attack targeting minority Shiites in Kabul in just over a month.

Hours later, the Islamic State affiliate in Afghanistan claimed responsibility for the attack, according to the SITE Intelligence Group, a U.S. monitoring service that tracks militant postings.

Afghan police said the bomber, who was on foot, had walked into the Shiite mosque in western Kabul where he detonated his explosives among a crowd of worshippers.

The United Nations Assistance Mission in Afghanistan said the explosion also wounded more than 50 people, many of them children. Earlier in the day, the Afghan authorities said at least 28 people were killed and 48 wounded.

In its statement, ISIS said the group's martyr hit a gathering of close to 1,000 inside a "temple of Shiite polytheists" in Kabul and detonated his vest bearing 35 pounds of explosives, SITE said. ISIS claimed nearly 200 Shiites were killed and wounded. However, militants often exaggerate their claims.

Sunni extremists such as the Taliban and ISIS militants view Shiites as heretics and apostates and frequently target Shiite mosques and public gatherings.

"This appalling attack on worshippers is an atrocity," the statement quoted Pernille Kardel, the Secretary-General's Deputy Special Representative for Afghanistan. "UNAMA expresses its revulsion at this latest effort by extremists to stoke sectarian violence in Afghanistan."

Monday's bombing hit during a prayers ceremony commemorating 40 days since the anniversary of the death of Imam Hussein, the slain grandson of the Prophet Muhammad. The ceremony is known as Arbaeen, meaning 'forty' in Arabic. Hussein is a revered Shiite martyr who was killed in 680 A.D. in the city of Karbala in present-day Iraq.

In early October, militants attacked another Shiite ceremony at a shrine in Kabul, commemorating the anniversary of Hussein's actual death. That attack killed 17 people, mostly worshippers but also several policemen. A day later, a similar attack struck Shiites in the city of Mazer-e Sharif in northern Balkh province, killing at least 14 people.

The ISIS affiliate in Afghanistan also claimed responsibility for one of those two attacks, the U.N. statement said.

Faredoon Obiadi, head of the criminal investigation department for the Kabul police, said the attacker in Monday's bombing walked into the Baqir-ul Ulom mosque and mingled among the crowd on the first floor of the two-story building where he detonated his explosives.

"Suddenly, a huge explosion happened, then everything went dark," said Ewaz Ali, 50, who was inside the mosque but suffered only minor wounds.

Kardel from UNAMA added in her statement that "religious and ethnic tolerance are values the Afghan people hold strong."

"I urge the Afghan authorities to do everything possible to defend Afghans of all faiths," she added.

U.S. Gen. John W. Nicholson, commander of the U.S.-led Resolute Support Mission in Afghanistan, condemned the bombing.

"On behalf of the men and women of Resolute Support, we offer our condolences to the families of the innocent men, women and children killed and wounded in today's attack," Nicholson said. "We will continue to stand with our Afghan partners and do everything possible to secure a peaceful, stable Afghanistan."

Shiites in Afghanistan make up an estimated 15 percent of the country's population of around 30 million. Their public celebrations and commemorations were largely banned during the five years when the Taliban controlled the country. But Afghanistan's Shiites have become more public since the extremists were overthrown in the U.S. invasion of 2001.

In July this year, a suicide bomber targeted ethic Hazaras, who are mostly Shiite, as they marched through central Kabul to protest discrimination. At least 80 people were killed and more than 200 were wounded in that attack, which was claimed by the Islamic State group.

In 2011, at least 54 people were killed when a suicide bomber detonated his explosives at a Shiite shrine in Kabul where hundreds of people had gathered to mark the Ashoura.

The Islamic State group emerged for the first time last year in Afghanistan as an offshoot of the militant group fighting in Iraq and Syria. Analysts believe the affiliate in Afghanistan is mostly made up of disenfranchised Taliban fighters.

The Afghan group calls itself the Khorasan Province — following the style of other IS offshoots, such as the one in Egypt which calls itself Sinai Province — and has battled both Afghan forces and the Taliban. It has attempted to carve out an enclave in Nangarhar, a rugged eastern province bordering Pakistan.

The U.S. State Department has added the ISIS Afghan affiliate to its list of foreign terrorist organizations.