Stunned students demonstrated outside Kabul University on Tuesday after at least 22 people were killed in a brutal, on-campus attack claimed by the Islamic State group.

Holding banners stating: “Stop Killing Us”, the small gathering came as Afghanistan observed a national day of mourning and the first funerals were expected.

Monday’s assault at the popular university near central Kabul saw three attackers – one of whom blew himself up – rampage through the campus, shooting students in their classrooms.

IS also claimed a similar attack on an educational centre in Kabul less than two weeks ago that killed 24 people.

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.

The insurgent group have said they were not involved in Monday’s attack, 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 Kabul administration, accusing the government of harbouring and assisting militants.

Fraidoon Ahmadi, a 23-year-old student, told AFP on Monday he was in class when gunfire broke out.

“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,” Ahmadi said.

He said he and other students were besieged for more than two hours before being rescued.

Images posted online showed what appeared to be the bodies of slain students lying by desks and chairs.

Zalmay Khalilzad, the US special envoy who helped bring the warring Taliban and Kabul 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 the terrorist group.

President Ashraf Ghani has vowed to take revenge for the assault, with an investigation underway to determine how the gunmen entered the university with weapons.