At least 21 people died in an armed assault on Bacha Khan University in Charsadda, about 50 kilometres (30 miles) from the city of Peshawar, where witnesses reported two large explosions as security forces moved in under dense fog to halt the bloodshed.

Police, soldiers and special forces swarmed the university from the ground and the air in a bid to shut down the assault, as television images showed female students running for their lives.

Source: b'Security forces at Bacha Khan university\xc2\xa0| Source: AFP'

"The death toll in the terrorist attack has risen to 21," regional police chief Saeed Wazir told AFP hours after the alarm was first raised. He said the operation had ended and security forces were clearing the area, with most of the student victims shot dead at a hostel for boys on the campus.

Military spokesman Major General Asim Bajwa said on Twitter that four attackers had been killed. Students spoke of one hero teacher -- named by media as Syed Hamid Hussain -- fighting back against the intruders, shooting his weapon in a bid to protect his charges.

Geology student Zahoor Ahmed said his chemistry lecturer had warned him not to leave the building after the first shots were fired. 

"He was holding a pistol in his hand," he said. "Then I saw a bullet hit him. I saw two militants were firing. I ran inside and then managed to flee by jumping over the back wall."

Another student told television reporters he was in class when he heard gunshots. "We saw three terrorists shouting, ‘Allah-o-Akbar!’ and rushing towards the stairs of our department," he said. "One student jumped out of the classroom through the window. We never saw him get up."

He also described seeing the chemistry professor holding a pistol and firing at the attackers. "Then we saw him fall down and as the terrorists entered the (registrar) office we ran away." Witnesses said dozens of personnel in combat fatigues and carrying automatic weapons had descended on the campus after the attack began, as helicopters buzzed overhead and ambulances raced to the scene.

Officials at hospitals in the city confirmed they were receiving injured patients, and Shaukat Yousafzai, provincial information minister told media that some of the injured were being taken to Peshawar. 

Source: b'A teacher after being rescued\xc2\xa0| Source: Reuters'

No group immediately claimed responsibility for the attack, which had echoes of a Taliban assault on an army-run school in Peshawar in December 2014 that killed more than 150 people, most of them children.

Feature image source: Twitter/@Pukhtoogle