The attacker blew himself when the prayers were in progress at the mosque in the Anbar tehsil of the agency bordering Afghanistan.
"A suicide bomber was in the mosque. He shouted 'Allahu Akbar' and blew himself up," Assistant Political Agent Naveed Akbar told reporters.
He said that Friday prayers were being offered around 2 PM when the powerful blast took place.
At least 25 people were killed in the attack and 29 others injured, Pakistani media reported, citing officials.
More From This Section
Rescue teams and police rushed to the spot. The bodies and the injured are being shifted to local hospitals for medical treatment.
Injured were also taken to hospitals in Bajaur Agency, Charsadda and Peshawar for treatment.
There was no immediate claim of responsibility, but Pakistani Taliban routinely targets courts, schools and mosques.
Prime Minister Nawaz Sharif has expressed his grief over the loss of lives in the blast.
The attack came on a day when Sharif vowed to continue the war against militancy and terrorism till elimination of the last terrorist.
The army had launched operation 'Zarb-e-Azb' in June 2014 to flush out militant bases in the northwestern tribal areas.