Militants attacked a military convoy in Pakistan's restive northwest Saturday, the latest episode in a surge of violence during an army offensive to drive the Taliban from the region's Swat Valley.

The Taliban have vowed a campaign of retaliatory attacks for the military offensive, and a series of bombings and shootings have hit security forces and civilian targets, including a marketplace and a bus stop.

On Friday, an attacker wearing an explosive vest blew himself up inside a packed mosque during prayers, killing at least 30 and wounding 40 more in Haya Gai village in Upper Dir, a rough and tumble district next to Swat.

The motive for such attacks on civilians is rarely clear, but it could be partly an attempt to use violence and intimidation to weaken public support for the army's operation.

On Saturday, a military convoy was attacked near Sakhakot town in Malakand, a region that borders Swat, the Pakistani army said in a statement. A gunbattle erupted and casualties were expected, though more details were not immediately known, it said.

Militants in Pakistan and Afghanistan have often killed scores of civilians in attacks that have included mosques and funerals.

No one claimed responsibility for Friday's mosque attack, but a local government official blamed the Taliban and said it was probably retaliation for the Swat offensive.

It was unclear whether any military figures or prominent anti-Taliban local officials were in attendance at the mosque.

A man wearing an explosives vest entered the mosque but was recognized as a stranger by some worshippers. 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.

Waliullah Khan, a village resident, said he was on his way to the mosque when he heard an explosion.

"I rushed there and saw smoke and dust," said Khan, who helped transport wounded people to the hospital. "Human body parts were lying there, there was blood and people were crying in pain. I counted at least 15 bodies."

Police Chief Ejaz Ahmad said the confirmed death toll was 30, but the number was expected 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 violated a peace deal with the government that gave them control of the valley by advancing into nearby Buner district just 60 miles from Islamabad, the capital.

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

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

Richard Holbrooke, the U.S. special envoy to Pakistan and Afghanistan, said Friday the offensive appeared to be clearing Swat of militants, though handling the refugee crisis would be "the real test" of success.

The military said this week that major population centers and roads leading to the valley were rid of Taliban resistance but isolated violence would likely continue for some time.

President Asif Ali Zardari has ordered 2,500 former military personnel to form a security force for the Swat region, his spokesman Farhatullah Babar said Saturday.