The three attackers killed at least 19 people including students before Afghan security forces shot the gunmen dead, authorities said.
Most of the casualties were students and there were fears the death toll could climb further with some of the wounded said to be in critical condition.
Shortly after the attack began the Taliban issued a statement denying responsibility.
Policemen stand guard at an entrance gate of the Kabul University in Kabul on November 2, 2020.
The Taliban said they were not involved, but Vice President Amrullah Saleh blamed the insurgent group and their supporters in Pakistan, even as he acknowledged an intelligence failure.
Video footage from the scene showed students walking and running away from the university, with the sound of gunfire in the background.
Students of the Kabul University escaped the compound with many climbing the boundary walls after the three assailants stormed the varsity, Tolo News said, citing sources. Interior Ministry spokesman Tariq Arian said the fighting was ongoing as security forces surrounded the campus.
Fraidoon Ahmadi, a 23-year-old student, told AFP he was in class when gunfire broke out at the university.
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.
Whatsapp is launching awesome new features, know about them
The WhatsApp FAQ page also has a precautionary note which advises users to use disappearing messages with trusted individuals. Right now, multimedia files are automatically downloaded in WhatsApp , and many times the data becomes more expensive.
The attack came as the insurgents are continuing peace talks with the USA -backed government.
Violence has plagued Afghanistan while government and Taliban negotiators have been meeting in Qatar to try to broker a peace deal and as the United States brings home its troops.
Kabul police spokesman Ferdaws Faramerz said all of those killed were students - 10 of them women.
Nowhere and no-one seems secure in Afghanistan's terrifying everyday violence.
Pakistan on Monday strongly condemned the "mindless attack at Kabul University", that has resulted in the loss of 19 people and injuries to many more.
"Books, pens and students are no longer safe", lamented one Afghan journalist on Twitter in response to Monday's attack.
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. Those negotiations, taking place in the Gulf Arab state of Qatar, aim to help the US finally withdraw from America's longest war, though daily bloodshed continues and an Islamic State affiliate launches its own attacks on Shiites in the country.
"The two fighters targeted the graduates with automatic weapons. then clashed with security forces".
That, and the stalled peace talks, have left many wondering: how and when will it ever end?