KABUL — An hours-long siege on Kabul University claimed by the Islamic State left at least 22 dead and 22 wounded Monday after two gunmen stormed the campus, took several students hostage and battled security forces for hours before the scene was cleared and all hostages were freed.

The attack in Afghanistan's capital began with an explosion at the gates of the university just before 11 a.m. Monday. Thousands of students fled, but a number trapped inside began posting to social media, describing seeing classmates gunned down.

“God give patience, my classmates martyred and wounded in front of my eyes, and I am taken hostage,” Qaseem Kohestani, a fourth-year student at the university’s public policy school, posted to Facebook.

A law student told The Washington Post that dozens of students and some professors were taken hostage in the attack. The student spoke on the condition of anonymity because of security concerns.

Afghan police special forces were dispatched to the scene. ­Coalition forces from the U.S.-led Resolute Support Mission in Afghanistan “provided support” to Afghan security forces during the operation, according to a military official who spoke on the condition of anonymity in line with Pentagon regulations. 

After an assault that lasted over five hours, the Interior Ministry declared the campus secured. The ministry said hundreds of students were rescued by Afghan security forces.

Afghan President Ashraf Ghani’s office condemned the attack and declared a national day of mourning Tuesday.

The Islamic State asserted responsibility for the attack in a statement released by the group’s media arm Monday night. The Taliban denied involvement in a statement released shortly after the attack began.

Monday’s siege bore hallmarks of past attacks on similar targets. In 2018, the Islamic State asserted responsibility for an attack on a shrine near Kabul University where Afghanistan’s Shiite ethnic Hazara community had gathered to mark the Persian new year. And in 2016, the Taliban attacked the American University in Kabul, killing 11 and wounding 30 in an assault that trapped some students all night as a gun battle raged for nine hours.

This is the second significant attack targeting civilians in Kabul in recent weeks. Last month, a suicide attack on an education center in west Kabul killed 24 people, mostly students, and wounded 70 others. The Islamic State also asserted responsibility for that attack.

Overall, large-scale attacks in the Afghan capital have decreased in recent months. The Islamic State group was weakened by Afghan military operations last year supported by U.S. air power that pushed it from strongholds in the country’s east. And large Taliban attacks in urban areas decreased significantly after the United States and the Taliban signed a deal in February on the withdrawal of U.S. forces.

But a handful of Islamic State-claimed attacks have continued to target minority groups in Kabul, including the Hazara community.

Many senior Afghan officials accuse the Taliban of playing a role in attacks claimed by the Islamic State.

Afghan Vice President Amrullah Saleh linked the Taliban to the university attack in a tweet Monday, saying the group “won’t be ever able to wash their Conscience of this stinking & non justifiable attack.” Ghani’s spokesman tweeted that the Taliban is targeting academic sites after suffering defeats in the country’s south.

The Taliban denies the accusations but has increased violence in other parts of the country despite ongoing peace talks with representatives of the Afghan government in Doha, Qatar.

The peace talks began in September but have failed to make significant progress.

The latest report from the U.N. Assistance Mission in Afghanistan said civilian casualties were down across the country from January through September — the lowest in any similar period since 2012. During that period, 2,117 civilians were killed and 3,822 wounded, a 30 percent drop in casualties compared with 2019.

But the report does not take into account a large Taliban assault in Helmand province that began last month and is ongoing.

The clashes have displaced thousands of civilians and are estimated to have killed and wounded dozens.