Mashal Khan and his friend Abdullah were attacked in the premises of the Abdul Wali Khan University in Mardan where at least 25 policemen were present.
Condemning killing of a student at a university in Mardan, Pakistan Tehreek-i-Insaf (PTI) chief Imran Khan has said that law of jungle can not prevail in Khyber Pakhtunkhawa, a province ruled by the PTI.
Reacting to the incident, Imran Khan voiced grief over the killing on micro-blogging website and underscored the need for a firm action against the perpetrators.
He added that five students were injured in clashes but police managed to bring the situation under control.
A group of about 10 students shouted "Allahu Akbar" during the attack on fellow student Mashal Khan, who was stripped naked and beaten with planks until his skull caved in as other students looked on, video obtained by Reuters showed.
The mob first beat him to a pulp and then shot him dead.
The police, when alerted, reached the site of the attack and rescued Abdullah, after which the mob set its sights on Mashal, who was in the hostel at the time, the eyewitness said.
The student, Mashal Khan, studied at the university's journalism department.
This event took place in the afternoon when a mob of students shot Mardan in the head and chest.
Khan was assaulted by a large group of students and appears to have succumbed to a gunshot wound, the DIG was quoted as saying in the Dawn newspaper. The campus was shut down following the incident until further notice and its hostels vacated to avoid a further escalation of violence.
Blasphemy is a highly sensitive topic in the country and a capital crime that has hundreds languishing on death row.
The government has recently vowed to combat the sharing of blasphemous content on social media.
At least 65 people have been murdered in Pakistan after being accused of blasphemy since 1990, a recent think tank report said.