Stunned Kabul University students vowed Tuesday to continue their education despite a brutal attack on their campus by the Islamic State group that killed 22 people.

As the first funerals took place, many students returned to see the carnage left after Monday's assault, staging a rally and holding banners that read "Stop Killing Us".

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.

"Today, when I came here and saw these classes, I felt like that there was no sign of a university anymore," Sami Ahmadi, who survived the onslaught, told AFP.

"This is the peak of terror and this is not in any system or religion."

Officials blamed the Taliban for the attack, saying three militants evaded security at the central Kabul campus. One blew himself up, they said, while the other two rampaged through the site, shooting students in their classrooms.

The Taliban denied responsibility, however, and the attack was claimed by rival militant group Islamic State, which said two of its fighters carried out the assault.

"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.

Bullet riddled walls and burnt desks and chairs bore testimony to the chaos that sent hundreds of students fleeing onto the streets while others barricaded themselves into rooms.

Two gaping holes created by explosives were evidence of how Afghan special forces dropped from the ceiling of a classroom to save students.

"My message to the terrorists is that we will never stop," said 21-year-old Mohammad Baqir Alizada, who attends a nearby university.

"At any cost, we will come again and work for a prosperous and free Afghanistan."

With the country holding a national day of mourning, fellow student Bashamal Sahak from Kabul University said there was no choice but to continue his studies and "fight them through knowledge".

A journalist walks inside a damaged classroom a day after gunmen stormed Kabul university
A journalist walks inside a damaged classroom a day after gunmen stormed Kabul university AFP / WAKIL KOHSAR

"We know one day they will kill us too. But we will never give up," he wrote on Facebook.

Public administration student Mohammad Rahid, who was killed in the attack, had found fame on campus for his motivational videos that he posted online.

"Life is full of struggle, full of pain, full of problems and full of sorrow," Rahid says in one of his recent clips.

"But still you see smiles on our lips. Because time will pass anyway and we have to live," he adds, now denied the joy of graduating.

Monday's attack was the second such assault on an educational centre in Kabul claimed by IS in less than two weeks. The previous one killed 24 people.

The Taliban said they were not involved, but Vice President Amrullah Saleh blamed them and their supporters in Pakistan.

The Taliban have in turn blamed "evil elements" that have "sought refuge" with the Afghan government.

Zalmay Khalilzad, the US special envoy who helped bring the warring Taliban and Afghan government together for talks, urged the two sides to accelerate a political settlement.

"This barbaric attack is NOT an opportunity for the government and the Taliban to score points against each other. There is a common enemy here," he tweeted.

"Deny ISIS or any other terrorist the space to carry out these inhumane acts," he added, using another name for IS.

France condemned the "terrorist attack" as it called for an "immediate ceasefire" in Afghanistan's long-running conflict.