At least 35 students and professors were killed and many more were wounded in an armed attack on Kabul University on Monday, which was claimed by the ISIS group.
Three gunmen stormed the university building on Monday morning, marking the second time in less than two weeks that an educational institution in the capital was targeted by ISIS extremists.
The terror group said two of its fighters carried out the late morning attack.
"Two Islamic State fighters managed to attack a gathering set up by the Afghan government at the Kabul University for the graduation of judges and investigators after completing a course at the university," the group's propaganda arm Amaq said.
"The two fighters targeted the graduates with automatic weapons... then clashed with security forces."
An Afghan soldier told The National that while the campus had been evacuated, many of those wounded remained inside as police faced off with assailants and eventually killed them all.
Blasts continued to be heard sporadically as attackers and security troops faced off for more than five hours.
Students posted accounts of the attack on social media as police surrounded the sprawling campus.
"Please God give me patience. My classmates died or were injured before my eyes," one of the students posted on his Facebook page. "We have also been taken as hostages. No security has arrived."
The Interior Ministry said an explosion preceded the first round of shots.
Kabul University had been receiving threats for nearly three years, an injured professor told The National.
"About three years ago, we were told to be very cautious because the Taliban were trying to attack the university," he said.
The university buildings are fitted with heavy metal doors and windows for such situations and staff and students had been locked in by security forces, said the professor, who has been teaching at the university for five years.
But witnesses said the assailants managed to enter the law faculty building.
ISIS later claimed responsibility the attack, the group's Amaq News Agency said.
In a message posted on Telegram, the group claimed to have "killed and injured 80 Afghan judges, investigators and security personnel" who gathered on completion of a training course.
In a Tweet, Taliban spokesman Zabihullah Mujahid said the group was not behind the university attack.
Video posted on Twitter by the Afghanistan's largest broadcaster, Tolo news, showed students fleeing as gunshots are heard in the background.
"When we heard the attack, everyone panicked and started running around because no one knew what to do," law student Mohammad Wasel told The National.
"A few of us jumped the university walls near our building and escaped to safety."
The attack began as Afghan and Iranian officials were inaugurating a book exhibition at the university, Tolo reported.
"We strongly condemn today's terrorist attack on Kabul University," said President Ashraf Ghani's spokesman, Sediq Sediqqi.
"We fully believe in the strength of our security forces in eliminating the terrorists as soon as possible.
"After their disgraceful defeat of terrorists in Helmand, these groups are now targeting academic institutes."
Kabul was hit in another attack earlier on Monday. A bomb blast in the Khwaja Sabz Posh district wounded a member of the security forces and a civilian.
Kabul police said the Posh district explosion was caused by a magnetic roadside bomb that detonated about 7.35am.
Universities in Kabul are often the targets of militant attacks.
Last year, a bomb outside of the Kabul University campus gates killed eight people. In 2016, gunmen attacked the American University in Kabul, killing 13.
"The recent attacks show that the enemies of Afghanistan see educated Afghans as targets," Ali Doosti, a student who escaped Monday's Kabul attack, told The National.
"They are doing everything in their power to stop our education. When I heard the gunshots today, I thought that these people are against my education."
Mr Doosti said the incident motivated him to "fight back" by completing his education.
"This is the only way we can secure our future and the future of our country," he said.
Last month, ISIS sent a suicide bomber into an education centre in the capital's mainly Shiite neighbourhood of Dasht-e-Barchi, killing 24 students.