PESHAWAR, PAKISTAN - A group of militants stormed a university in volatile north-western Pakistan on Wednesday and killed at least eight people, officials said, with firing inside the campus still going on and two explosions heard.

Deputy Inspector General Saeed Wazir said at least three students had been killed in the attack, and a spokesman for the rescue workers said eight bodies had been recovered so far.

Four of the gunmen have been killed by security forces and the army has contained the militants to two blocks inside the university, a spokesman for the army said on twitter. Police said earlier that other attackers were believed to be at large on the second and third floors of the campus buildings.

The militants, using the cover of thick, wintry fog, scaled the walls of the Bacha Khan University in Charsadda, north-western Khyber Pakhtunkhwa province, before entering buildings and opening fire on students and teachers in classrooms and hostels, police said.

Police inspector Wazir said 70 percent of students had been rescued.

"All students have been evacuated from the hostels, but militants are still hiding in different parts of the university and some students and staff are stuck inside," he said, adding that it was unclear how many gunmen were involved.

Television footage showed soldiers entering the campus as ambulances lined up outside the main gate and anxious parents consoled each other.

Pakistan, which has suffered from years of militant violence, has killed and arrested hundreds of suspected militants under a major crackdown launched after a massacre of 134 school children in December 2014 in the northwest.

The 2014 school attack by six gunmen believed linked to the Pakistani Taliban hit a raw nerve in Pakistan and was seen as having hardened Pakistan's resolve to fight jihadist militants along its lawless border with Afghanistan.

Vice Chancellor Fazal Rahim told reporters that the Bacha Khan University teaches over 3,000 students and hosted an additional 600 visitors on Wednesday for a poetry recital.

Shabir Khan, a lecturer in the English department, said he was about to leave the hostel for the department when firing began.

"Most of the students and staff were in classes when the firing began," Khan said. "I have no idea about what's going on but I heard one security official talking on the phone to someone and said many people had been killed and injured."