Rescue workers transport an injured person to the hospital after gunmen attacked the Directorate of Agriculture Institute in Peshawar, Pakistan December 1, 2017
Tehreek-i-Taleban Pakistan has claimed the attack
The number of casualties is expected to rise, the media quoted security officials and doctors as saying. Twenty-five others were injured in the horrific attack.
The killings began early in the morning after three loud explosions were heard. Firing broke out at the hostel after three to five burqa-clad suspects entered the building, Geo news reported.
Ordinarily, there are around 400 students at the hostel but there were only some 150 on Friday on account of Eid Milad-un-Nabi, the birthday of Prophet Mohammad, said a student who witnessed the attack.
As two militants began firing, the frightened students ran to take shelter. Some were shot and wounded while others jumped out of the windows, the witness said.
The attackers, who arrived in a rickshaw, first shot the guard at the gate and then proceeded to the hostel, according to police.
Security forces, initially stunned by the attack, then took on the terrorists.
"A total of five terrorists have been killed. Nine people including eight students and a guard have been killed. While 25 others, including students, police and troops, are injured," Peshawar police officer Bashir Dad told Efe news.
The Tehreek-e-Taleban Pakistan, the country's main Taleban group, claimed the attack in a statement that specified that three of its combatants carried it out.
It said the attackers had killed dozens and claimed that the institute was not a university but "an undercover centre" of the Pakistani intelligence agency the ISI.
"This attack is a reaction to the continued brutalities by the intelligence agencies on Tehreek-e-Taleban Pakistan and innocent people especially prisoners and clerics," the group said.
Suicide jackets, three grenades, two bombs and a pistol were recovered in the hostel building.
Khyber-Pakhtunkhwa Chief Minister Pervaiz Khattak said that although the police were "always alert, this incident happened suddenly", Dawn news reported.
"The police arrived and took control... Security measures have been taken keeping Eid Milad-un-Nabi in view. Our police was there soon after the firing started... Right now we are facing difficult circumstances."
This is not the first attack on a university in Pakistan.
A Taliban attack on the Bacha Khan University in Charsadda in January 2016 left 25 people dead.
The worst attack against an educational institution occurred in December 2014 when insurgents attacked a school in Peshawar, leaving 151 people dead, mostly children.
Pakistan has launched several military operations against insurgent groups throughout the country in recent months following multiple major attacks in 2017.
Peshawar has for decades witnessed militancy at close quarters as it is seen as a frontline in the war against terrorism as well as due to its proximity to the restless tribal areas and the Pakistan-Afghan border.