PESHAWAR, Pakistan - An attacker wearing an explosive vest blew himself up inside a packed mosque during Friday prayers, killing at least 30 and wounding 40 more in northwest Pakistan, officials said.

No one claimed responsibility for the attack, but a local government official blamed the Taliban and said it was probably retaliation for a Pakistani military offensive against extremists in the Swat Valley region.

It was unclear whether any military figures or prominent anti-Taliban local officials were in attendance at the Sunni mosque in the village of Haya Gai in Upper Dir, a rough-and-tumble district next to Swat.

The village is 65 miles north of Peshawar and 30 miles northwest of Mingora, the largest city in Swat.

The Taliban has threatened a campaign of revenge attacks for the offensive. Although most of the bombings have targeted security forces, extremists have also targeted civilians - most recently with a marketplace blast in Peshawar that killed six civilians.

The motive for such attacks on civilians is rarely clear, but it could be partly an attempt to intimidate the public and weaken its support for the army operation.

Police said a man wearing an explosive vest entered the mosque but was recognized as a stranger by some worshipers. When they confronted the man, he blew himself up, said Atlass Khan, an Upper Dir police official.

"People tried to intercept him because he looked like an outsider, someone who does not belong to this area," Khan told the Associated Press by phone.

Extremists in Pakistan and Afghanistan have killed large numbers of civilians in attacks on places where people tend to congregate, such as mosques. On March 27, a suicide bomber blew up a packed mosque near the Afghan border during Friday prayers, killing 48 people.

Police Chief Ejaz Ahmad said the confirmed death toll in yesterday's mosque blast was 30, but he said he expected the number to increase because there were more body parts to be counted and some of the 40 wounded were in critical condition.

Atif-ur-Rehman, a top official in Upper Dir's government, blamed the Taliban, though he said the investigation was in its early stages.

"It is obvious. They are Taliban," he told AP. "We can say it seems to be a reaction to the offensive in Swat."

Pakistan launched its Swat offensive in late April, after the Taliban advanced into Buner district, just 60 miles from Islamabad, the capital, violating a peace deal that had given the Taliban control of the valley.

Washington strongly backs the operation and sees it as a test of Pakistan's resolve to beat al-Qaeda and Taliban extremists implicated in attacks on Western forces in neighboring Afghanistan.

But the generally broad public support in Pakistan for the operation could falter if extremist violence widens or if the government fails to successfully resettle three million refugees from the fighting.