At least 22 people have been killed by gunmen who stormed Kabul University before engaging security forces in an hours-long battle on Monday.
A spokesman for the Afghan interior ministry said the attack was eventually stopped when three gunmen were killed.
A regional Islamic State group claimed responsibility in a statement.
The attack began shortly before the expected arrival of government officials for an Iranian book fair and continued for several hours.
A further 22 people were wounded by the attackers.
Tuesday has been declared a national day of mourning by the government.
The Taliban denied involvement and condemned the attack shortly after it began on Monday. Hours later the Islamic State group issued a message on the Telegram app saying it had targeted “the graduation of judges and investigators working for the apostate Afghan government”.
IS has previously targeted education centres in Afghanistan, including an attack outside a tuition centre in Kabul last month that left 24 people dead. The group also claimed responsibility for a 2018 attack in front of Kabul University in which dozens were killed.
In a statement issued by the presidential palace, President Ashraf Ghani said authorities would “take revenge for this senseless attack”.
Video footage from the university campus on Monday showed students running away from the site with the sound of gunfire in the background. Some scaled walls in an effort to escape. One of the attackers detonated explosives at the beginning of the assault, according to a spokesman for the Interior Ministry.
Fraidoon Ahmadi, a 23-year-old student, was in class when the gunfire started: “We were very scared and we thought it could be the last day of our lives. Boys and girls were shouting, praying and crying for help,” he told the AFP news agency.
Another witness, Fathullah Moradi, told Reuters the gunmen were “shooting at every student they saw” and “even shot at the students who were running away”.
Violence in Afghanistan has worsened in recent months even as the Taliban conducts peace talks with the government in Doha, Qatar. The talks, which follow an earlier peace agreement between the Taliban and the US in February, have stalled over preliminary issues.
A senior UN official told the BBC last week that al-Qaeda was still “heavily embedded” within the Taliban, despite assurances from Taliban officials to the US that it would sever ties with the terror group.
Separately on Monday, a vehicle hit a roadside mine in the country’s southern Helmand province, killing at least seven people, most of them women and children, according to the provincial governor’s spokesman Omer Zwak.
Nowhere and no-one seems secure in Afghanistan’s terrifying everyday violence. “Books, pens and students are no longer safe,” lamented one Afghan journalist on Twitter in response to Monday’s attack.
The bloody assault on Kabul University came about a week after a devastating attack on an education centre in the city which killed more than 40 young students. That attack, in a predominantly Shia Muslim neighbourhood of Kabul, was claimed by the Islamic State group. The Taliban were quick to say the Kabul University raid wasn’t their doing, pointing the finger instead at “evil elements” linked to the “Kabul administration”.
The Afghan government now regards these despicable attacks on civilians as the work of a seamless web of groups with guns determined to wreak havoc and wreck hope in Afghanistan. Afghans are reeling – from this violence and from the escalating war between security forces and Taliban fighters on front lines across the country.
That, and the stalled peace talks, have left many wondering: how and when will it ever end?
You may also be interested in: