Dozens of people were also injured, with more deaths feared.
Taliban and al-Qaeda militants are active in the restive tribal region along the Afghan border.
"It was a suicide attack. The bomber was wearing about 8-10kg of explosives and was on foot. He detonated in the main prayer hall," deputy chief Khalid Mumtaz Kundi told the AFP news agency.
Senior government official Khalid Mumtaz Kundi said ballbearings had been found at the site, which indicated a suicide attack.
"The toll could rise as many wounded are in serious condition," he said.
Video footage of the scene showed shoes and clothing scattered through the mosque and prayer mats covered with blood.
Another official, Sayed Ahmed Jan, said the bomb went off seconds after the prayers finished.
Some witnesses told reporters a teenage boy had detonated an explosives vest amid the worshippers. They said the roof of the mosque then caved in.
The blast comes as Muslims in Pakistan and elsewhere are observing the holy month of Ramadan.
"Whoever did it in the holy month of Ramadan cannot be a Muslim," said Saleem Khan, 21, who was injured. "It is the cruellest thing any Muslim would do."
Another witness, Haji Zarmeen, told Reuters there were still bodies trapped in the wreckage.
Many of the injured people were taken to the Hayat Abad Medical Complex in Peshawar, about 16 miles (25km) away.
No group has yet said it was behind the attack.
But there has been a sharp rise in militant attacks in Pakistan since May, the same month US commandos killed al-Qaeda leader Osama Bin Laden in a raid in Abbottabad.
The US has pledged to pursue militants using the border region as a sanctuary from which to launch attacks in Pakistan and Afghanistan.
On Friday, a US drone aircraft fired two missiles at a house in Shin Warsak in the South Waziristan tribal region, killing four people, intelligence officials said.
One security official told AFP that the house hit belonged to a tribal elder and that local militants had been there at the time.
The Khyber tribal region has been the scene of several deadly attacks in the past, many of which targeted mosques in order to cause as many casualties as possible. The area is home to a number of different militant groups who have been at war with each other and with the Pakistani forces.
It is not a region known for its sectarian violence and the militant groups that are currently based there tend to share a similar religious ideology. The Pakistani military has conducted sporadic operations against these groups, with mixed success.
The attacks in the area tend to be related to such operations. When army assaults escalate so do militant attacks. Whenever a drone strike takes place, retaliatory attacks usually follow.
This latest bombing comes amid renewed intensity in militant attacks across Pakistan after two months of relative quiet.