A suicide bomber shouted "Allahu akbar" and blew himself up in a packed mosque in northwestern Pakistan, killing at least 25 people and wounding 30.
A splinter group of the Pakistani Taliban, Tehreek-e-Taliban Pakistan Jamaat-ur-Ahrar (TTP-JA), claimed responsibility for the blast on Friday in Payee Khan.
The village is inside Mohmand Agency that is part of the lawless Federally Administered Tribal Areas (FATA) bordering Afghanistan.
The group said it was a revenge attack, accusing tribesmen in the area of launching an assault on its forces and of capturing militants and handing them over to the government.
"The suicide bomber was in a crowded mosque, he shouted 'Allahu akbar' (God is greatest) and then there was a huge blast," Naveed Akbar, deputy administrator of Mohmand Agency, told Reuters.
Akbar added that some fatalities appear to have been caused when part of the mosque caved in from the force of the blast.
Local tribal elder Haji Subhanullah Mohmand said local tribesmen had gathered a volunteer force, killed one insurgent and captured another.
Pakistan's frontier regions, which are deeply conservative and hard to access due to rough terrain, have long been the sanctuary of fighters from al-Qaeda, the Taliban and other militant groups.
In 2014 the army launched a major operation in other parts of FATA including North and South Waziristan against insurgents who routinely attacked government officials and civilians.
Pakistan Prime Minister Nawaz Sharif condemned the bombing and said the "attacks by terrorists cannot shatter the government's resolve to eliminate terrorism from the country".
Security in Pakistan has improved in recent years - the military says "terrorist incidents" dropped from 128 in 2013 to 74 last year - but Islamist extremists continue to stage major attacks.
A bombing of lawyers in the city of Quetta killed 74 people last month, an attack claimed by both the Islamic State and Jamaat-ur-Ahrar, a breakaway faction of the Pakistani Taliban.
Jamaat-ur-Ahrar also claimed the Easter Sunday bombing in a park in the eastern city of Lahore that killed 72 people, many of them children.
Most of the myriad militant groups that stage attacks inside Pakistan seek to overthrow the government to establish an Islamic theocracy and impose a stricter interpretation of the religion than is practised in much of the country.
Other armed groups based in the country target neighbouring Afghanistan and Indian-controlled Kashmir.