Four suspected attackers were killed in a battle that lasted nearly three hours.
Security forces continued to secure the campus, checking classrooms and dormitories, amid fears more bodies would be found.
There are conflicting reports about whether the Taliban militants carried out the assault
The group killed 130 students at a school in the city of Peshawar, 30 miles from Charsadda, in 2014.
About 3,000 students are enrolled at Bacha Khan but hundreds of visitors were also expected on January 20 for a poetry event.
Pakistani PM Nawaz Sharif said in a statement, quoted by Reuters news agency: “We are determined and resolved in our commitment to wipe out the menace of terrorism from our homeland.”
Attackers struck at around 09:30 local time, reportedly climbing over a back wall under cover of the thick winter fog.
Intense gunfire and explosions were heard as security guards fought the attackers.
Students and staff ran to find cover in toilets and examination halls.
Images from inside the university show a pool of blood on the floor of a dormitory and the charred corpses of two alleged militants lying on a staircase.
Nineteen bodies were taken to a local mortuary. It was not immediately clear if the attackers were among them.
A senior Taliban commander, Umar Mansoor, told media that the attack was in response to a military offensive against militant strongholds. He said four suicide attackers had carried out the attack.
The university is located in an open area some distance east of Charsadda town, surrounded by open agricultural fields.
Bacha Khan is a new university, founded in 2012, its website says.
Just days ago, some schools in Peshawar were closed by the authorities amid reports that militants were planning an attack.
Image source: Wikimedia Commons President-elect Donald Trump celebrated his election victory at the Ultimate Fighting…
Millions of voters across the US chose to return Donald Trump to the White House…
Donald Trump declares victory in the US election as he addresses jubilant supporters in Florida.…
Stocks around the world are rising as Donald Trump appears to be on the cusp…
Donald Trump has won Pennsylvania, North Carolina and Georgia and taken a lead over Kamala…
Quincy Jones, the celebrated musician and producer who worked with Michael Jackson, Frank Sinatra, Ray…