Three attackers reportedly wore women's burqas to reach the government research centre's gate in a rickshaw before opening fire to force their way into the building, targeting the student accommodation.
In the firefight that ensued they were confronted by police and paramilitary troops, who killed all the assailants.
Police chief Salahuddin Mahsud said troops were searching and clearing the building after eliminating the attackers, and television footage showed bullet holes in walls, bloodstains and broken glass.
Two soldiers, seven policemen, a reporter and a private guard are thought to have been injured as well as students.
Noor Wali, a 19-year-old student at the institute, said he hid from the gunmen for more than an hour with a badly injured friend.
"I rushed to the door and saw a fountain of blood pumping out of the shoulder of my roommate who was standing outside the room," he said.
"We took shelter inside the bedroom and were begging the injured student not to make any sound as the terrorists might hear it and kill us."
Authorities also seized an explosive vest, hand grenades and assault rifles, Mr Mahsud said, as well as rescuing many students in armoured vehicles.
Tehrik-e-Taliban Pakistan, the country's main Taliban group, claimed responsibility for the attack.
It was condemned by Pervez Khattak, chief minister of Khyber Pakhtunkhwa province.
"These terrorists have no religion as they attacked on a day which is very sacred and the nation was celebrating it," Mr Khattak said.
The college campus is thought to have been quieter than usual on Friday, when the attack took place, as Pakistan marked the birthday of the Prophet Muhammad.
The assault comes a week after a suicide bomber killed a top police official in the city, and follows weeks of anti-blasphemy protests in Islamabad that saw seven people killed and hundreds wounded in clashes with police.