Taliban spokesman Umer Mansour told journalists the attack at Bacha Khan University in Charsadda, northwestern Khyber Pakhtunkhwa province, was revenge for the death of militants at the hands of Pakistani security forces.
The claim came as the death toll rose to 19 dead and dozens wounded as the army hunted for any gunmen still holed up on the campus.
A security official said the death toll could rise to as high as 40 as the army cleared out student hostels and classrooms.
A spokesman for the rescue workers, Bilal Ahmad Faizi, said 19 bodies had been recovered including students, guards, policemen and at least one professor.
related reading
Suicide bomber kills 10 in Pakistan
Firing had ended after several hours and four militants had been killed, the army said, in an attack that comes a little over a year after Taliban gunmen killed 134 students at a military-run school in nearby Peshawar.
A senior security officer at the scene told Reuters 90 per cent of the campus had been secured and that 51 people were wounded.
The militants, using the cover of thick, wintry fog, scaled the walls of the university before entering buildings and opening fire on students and teachers in classrooms and hostels, police said.
The gunmen attacked as the university prepared to host a poetry recital on Wednesday afternoon to commemorate the death anniversary of Khan Abdul Ghaffar Khan, a popular ethnic Pashtun independence activist after whom the university is named.
Police inspector Saeed Wazir said 70 per cent of the 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 before the firing had stopped, 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.
Shabir Khan, a lecturer in the English department, said he was about to leave his university housing 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."
Pakistan, which has suffered from years of jihadist militant violence, has killed and arrested hundreds of suspected militants under a major crackdown launched after the massacre of school children in December 2014 in Peshawar.
The school attack by six Pakistani Taliban gunmen hit a raw nerve in Pakistan and was seen as having hardened Pakistan's resolve to fight militants along its lawless border with Afghanistan.
"We are determined and resolved in our commitment to wipe out the menace of terrorism from our homeland," Prime Minister Nawaz Sharif said in a statement after Wednesday's attack.
One witness told Reuters, "There was so much panic and fear that a friend of mine jumped from the university building," he said.
"The building is very high, yet he jumped from it in because he was so scared. We saw the militants chanting 'Allah is greatest'."