Thirty-two people were also injured in the attack.
Police go through weapons collected from the bodies of attackers after the shooting in Peshawar.
Tehreek-e-Taliban Pakistan, the Pakistani Taliban, has already claimed responsibility for the attack. A journalist and a university security guard are said to be among the injured. TTP spokesman Muhammad Khurasani said in an email that the fighters attacked "a secret office of Inter-Services Intelligence (ISI)".
Security has improved in Pakistan over the past few years but a spate of attacks in recent days, and a threat by hardline militants to unleash a new campaign against the government, has raised fears of bloodshed. "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.
Police and army troops summoned to the scene killed all of the attackers at the Agriculture Training Institute in the northwestern city of Peshawar about two hours into the attack, the military's press wing said.
He and another student rushed to his aid, and hid from the gunmen for nearly an hour before they were rescued by security forces.
United States president says Melania Trump 'truly loves what she is doing'
"The President, Barron, and I are very excited for our first Christmas in the White House ", said First Lady Melania Trump . She did a final check late Sunday after returning from the family's Thanksgiving at their home in Palm Beach, Florida.
Soldiers stand guard after an attack by Taliban militants in Peshawar. "The other student was pressing the wound with his hands to stop the blood and I had to put my hand on his mouth so that he can not scream", he said.
"We were sleeping when we heard gunshots".
Around eight to 10 people were reportedly evacuated by the security officials.
The country is tense after weeks of anti-blasphemy protests in Islamabad in which seven people have killed and hundreds wounded in clashes with police.
Peshawar Capital City Police Officer Tahir Khan and SSP operations were reported to have led the operation which has now been completed.