KABUL — The college prep class on the west side of Kabul was just getting underway Wednesday afternoon. All 500 seats in the private learning center were filled with high school students from the local Shiite Muslim community. Suddenly, a stranger strode into the ground-floor hall and detonated a suicide vest, witnesses said.

The room erupted in bloody mayhem, leaving at least 48 people dead and 76 wounded. 

“It was a horror scene. I saw dead bodies and scattered flesh,” said Mohammed Reza Hussaindad, 27, who works in a nearby bakery.

Rushing to the scene, he said, he saw some people searching for their children, others weeping. 

The suicide bombing at the Mowud Education Center in Kabul’s Dasht-i-Barchi district was one of the deadliest attacks in the city in the past several years. It underscored both the precarious security situation in the heavily policed capital and the relentless drive of militant groups, in the name of Islam, to decimate Muslim communities they regard as heretical. 

A spokesman for the Taliban insurgents denied a connection to the bombing, and no other group claimed it. But the attack bore the hallmarks of previous suicide bombings by the Islamic State militia, many of them at mosques, shrines and other targets in the same Shiite and ethnic Hazara area of Kabul.    

In a short message on social media, the Taliban spokesman said the group’s “mujahideen have no links with Kabul incident.” Nevertheless, the bomb attack came a day after the end of a ferocious five-day Taliban siege of the eastern city of Ghazni, and the successive urban attacks left Afghans feeling whipsawed and exhausted. 

The Taliban also claimed a ground attack early Wednesday in northern Baghlan province that killed as many as 44 Afghan police officers and soldiers, the latest in a succession of such assaults on security targets in scattered rural areas.

The attack on Ghazni, a provincial capital about 90 miles southwest of Kabul, left parts of the city in ruins, killed at least 120 members of the security forces and civilians, in intense fighting, and sent residents fleeing to the countryside before the insurgents retreated under pressure from Afghan forces backed by U.S. airstrikes. 

It was the most serious insurgent attack on an Afghan urban area since 2015, and it appeared to sabotage rising hopes for a truce during the next week’s Eid-al-Adha holiday and for revived peace talks in the 17-year conflict. It also put added pressure on the government of President Ashraf Ghani, which has scheduled parliamentary elections in October but may not be able to secure them.  

 The mood was angry as well as sorrowful several hours after Wednesday’s bombing at the learning center, after ambulances had rushed victims to hospitals and police had withdrawn from the site. A group of young men gathered outside the empty building, lighting candles for the dead among scattered shards of glass.

Some of them shouted angrily at no one, cursing the Ghani government and saying it did not care about protecting their community.  

The attack resembled a suicide bombing in March that wounded six students at another Shiite educational center in the same district.

In that attack, which was claimed by the Islamic State, a man wearing a suicide vest entered a classroom but failed to detonate his explosives and instead threw a grenade.

In the past year, the extremist Sunni militia has carried out numerous bombings in Kabul’s Shiite community, many of them on religious holidays, in an apparent attempt to foster hostility between the country’s minority Shiites and majority Sunni Muslims. The Islamic State views Shiites as heretics. 

The deadliest such attacks have included a bombing at a historic Shiite shrine that killed 30 people who were celebrating the Persian new year, another at a public gathering to commemorate a late Shiite militia leader, and a third at a school where people were registering for voter ID cards. 

Sayed Salahuddin contributed to this report.