The attack on Friday came as violence has surged in the region with security forces targeting militants.
The bombing occurred in Kohat, a district in Khyber Pakhtunkhwa province bordering Afghanistan, when an attacker apparently rammed an explosives-laden vehicle into the mosque, said Zulfiqar Hameed, the provincial police chief.
Hospital officials have confirmed that five police officers and 10 civilians were among the dead, Bilal Faizi, a senior rescue official said.
Most of those wounded were worshippers, he said. Some were in critical condition.
At least two armed gunmen also attempted to enter the police compound and exchanged fire with officers, police said.
Photos from the scene showed the outer wall of the police offices had collapsed and the mosque was badly damaged.
Smoke rose over the site after the blast, which witnesses and residents said was heard far away, followed by gunfire.
Prime Minister Shehbaz Sharif condemned the attack and expressed sorrow over the casualties.
He directed authorities to accelerate rescue operations.
No group immediately claimed responsibility for the attack, but suspicion was likely to fall on the Pakistani Taliban, formally known as Tehrik-e-Taliban Pakistan, or TTP.
The attack comes a day after a roadside bomb struck a security forces convoy in the northwestern Hangu district and killed six soldiers.
Government troops also conducted raids in various areas on Thursday and killed 10 militants believed to be members of the Pakistani Taliban, the military and police said.
Pakistani Taliban have stepped up attacks on police and civilians in recent years.
In 2023, a suicide bomber killed 101 people in an attack inside a mosque in Peshawar, the capital of Khyber Pakhtunkhwa province.
The group is separate from but allied with Afghanistan's Taliban, which returned to power in 2021.
Pakistan often accuses Kabul of sheltering the TTP and turning a blind eye to cross-border militant attacks.
The government in Kabul denies the allegations.