Attackers entered the university buildings, in Khyber-Pakhtunkhwa province, and opened fire at students and teachers in classrooms and dorms, according to police officials. Students told media they saw several young men wielding AK-47 guns storming the university housing, where many students were sleeping.
One faction of the Pakistan Taliban, the Dara Adma Khel splinter group, claimed responsibility for the attack.
However, the chief of the Pakistan Taliban, Fazlullah, condemned the attack in a statement, adding that those using the group's name would be brought to justice.
The university has over 3,000 enrolled students and was hosting an additional 600 visitors on Wednesday for a poetry recital on the death anniversary of the Pashtun activist Abdul Ghaffar "Bacha" Khan, the university's vice chancellor said.
"About 200 students have been safely evacuated from an examination hall in the university," said Shah Farman, the province's public health minister.
Local authorities announced the closure of all education institutions across Charsadda until Jan. 31.
Earlier, as police and soldiers rushed to the campus, the attackers traded gunfire with the troops, and several explosions were heard from the area of the university. The army said the attackers were contained in two university blocks before being killed.
Television footage showed heavy military presence at the university, troops rushing in and people fleeing. Ambulances were at the scene, and the wounded were being taken to the hospital.
Shabir Khan, a lecturer at the English department, said he was about to leave his housing for the department when the shooting began. "Most of the students and staff were in the classes when the firing began," he said.
On Tuesday a suicide bomber blew himself up close to a police checkpoint in the Jamrud area of northwestern Pakistan, killing at least 10 people and wounding more than 20.
At least 144 people, most of them children, were killed when armed men attacked the Army Public School in Peshawar on Dec. 16, 2014. Last month Pakistan executed four men linked to the massacre. The executions, which officials said were carried out by hanging at a prison in the city of Kohat, were the first in connection with the attack.
Al Jazeera and wire services