Students were gunned down "one by one" as they leapt from the windows of Kabul University classrooms when militants stormed the campus earlier this week, a survivor told AFP on Wednesday.

Officials said at least 22 people were killed and another 27 wounded when three gunmen rampaged through the university on Monday, spraying classrooms with bullets in an assault claimed by the jihadist Islamic State group.

The government insisted Wednesday that the Taliban were responsible, blaming an offshoot known as the Haqqani network.

Mohammad Qasim Kohistani, studying public policy at the university, described how the seven-hour attack unfolded at one of Afghanistan's top educational institutions.

"We were waiting for our teacher... suddenly, we heard loud sounds coming from the first floor," said the 22-year-old, who was in a second-floor classroom.

"We knew something was wrong; we started jumping from the windows."

Kohistani and some friends took refuge under a window ledge, a bloody scene unravelling above them, as the assailants went room to room searching for victims.

A damaged classroom at Kabul University after gunmen stormed the facility this week
A damaged classroom at Kabul University after gunmen stormed the facility this week AFP / WAKIL KOHSAR

"After a gunman took over our class he started shooting fleeing students from the window," said Kohistani.

"The other gunmen were shooting students one by one from close range," he added.

Hundreds of students fled -- some scrambling over perimeter walls and onto the streets, others barricading themselves inside rooms until being rescued by Afghan special forces.

Among those killed was Kohistani's best friend, Ahmad Ali, who stopped to help a female classmate, Roqia.

"He didn't jump from the window because Roqia had fainted," he explained.

Mohammad Qasim Kohistani stayed hidden for hours on campus
Mohammad Qasim Kohistani stayed hidden for hours on campus AFP / Wakil KOHSAR

"He wanted to save her but the gunman shot both of them in the head."

Kohistani, who sprained a leg when he jumped, hid for hours on campus.

"It was the most horrible moment of my life," he said.

"All through the day we were hearing their wails and cries for help but we were helpless."

Kohistani said the attackers had killed everyone in a classroom below his.

"I am still in trauma," he said. "Yesterday, I was not even able to talk."

Officials said two attackers were shot dead by security forces, while a third blew himself up during the assault.

The attack was claimed by IS, the second such assault on an educational centre in less than two weeks in the capital.

But the government said the Taliban were responsible.

"The organisers of this attack are from the Haqqani network ... and Haqqani network is an inseparable part of the Taliban," interior ministry spokesman Tariq Arian said in a statement.

The shadowy network has long been accused of carrying out brutal assaults on Western troops and civilians, and has been branded a terrorist group by Washington.

The Taliban have denied involvement.

Authorities are investigating how the militants managed to enter the campus with weapons, and have arrested 13 police officers for "negligence", Arian said.

Afghan security forces have been grappling with surging violence that has only worsened in recent months despite the government holding peace talks with the Taliban in Qatar.

Afghanistan held a national day of mourning on Tuesday, while students demonstrated outside Kabul University, holding banners which read "Stop killing us".