ISLAMABAD, Pakistan (CNN) -- A suspected suicide attacker detonated his explosives at a mosque in northwestern Pakistan during Friday prayers, killing at least 40 people and wounding dozens of others, a local police official said.
Residents were trying to stop the suspect from entering the main gate of the mosque when the explosion happened at about 3 p.m. (5 a.m. ET) in a village in the Upper Dir district of North West Frontier Province, said Atiq Ur Rehman, a district coordination officer told CNN.
Rehman said the blast wounded 80 people, 10 of them in critical condition.
The suspect was not from Hayagay Gharbi -- a village about 35 km (22 miles) from the Afghan border known for being against the Taliban, said Rehman, noting at least two instances in which residents staged roadblocks to keep militants from traveling through their area.
Upper Dir is a part of the Swat Valley, where the Pakistani military has waged a massive operation against Taliban militants, but the district has not been part of the ongoing military offensive.
It is the latest attack on civilians in northwestern Pakistan. Militants bombed a girls' school near Peshawar on Thursday, damaging several classrooms but resulting in no casualties.
The ongoing violence led U.S. envoy Richard Holbrooke to arrive in Pakistan on Wednesday to address the situation in the Swat Valley, telling Pakistan President Asif Ali Zardari, "We are committed to helping you."
"I hope the people of Pakistan will understand that our country has been in the lead role, coming out here quickly and giving more resources than the rest of the world combined to assist Pakistan," said Holbrooke, the Obama administration special representative to Afghanistan and Pakistan.
On Friday, Holbrooke met with Pakistan's army chief Gen. Ashfaq Kayani, a military spokesman confirmed without elaboration.
The United Nations said an estimated 2 million Pakistanis have been displaced by fighting between the Pakistani military and Taliban militants.
Earlier this week, militants in the tribal region of North Waziristan abducted more than 120 students and staff at a graduation ceremony at Razmak Cadet College. The Pakistani army rescued most of them, while remaining hostages were freed after tribal elders negotiated their release.
On Monday, militants bombed a bus station in the North West Frontier Province city of Kohat, killing two civilians and wounding 18, a police official said. Last week, a string of militant attacks in Peshawar and Dera Ismail Khan -- also located in the province -- killed 12 people.
There was no immediate claim of responsibility for any of the attacks. However, Pakistan's Taliban said it carried out a suicide attack in Lahore, Pakistan, on May 27 that killed 27 people.
The militants threatened to continue attacking cities in Pakistan until the military ends its operations against Taliban militants. As a result, Pakistani authorities increased security in Islamabad, Pakistan's capital city.
The Pakistani military has been conducting a month-long offensive against the Taliban, centered in the Swat region of North West Frontier Province.
CNN's Ingrid Formanek and Journalist Hasir Habib contributed to this report