ISLAMABAD – Pakistani villagers enraged with the Taliban after the bombing of a mosque battled the militants on Monday, underscoring a shift in public opinion away from the hardline Islamists.

The military has been fighting the Taliban in the Swat valley, northwest of the capital, for more than a month after the militants took advantage of a peace pact to conquer new areas.

In retaliation for the offensive, the Taliban have stepped up bomb attacks and are suspected of being behind a suicide blast at a mosque in the Upper Dir region, near Swat, that killed about 40 people on Friday.

Outraged by the attack, villagers formed a militia, known as a lashkar, of about 500 men and began fighting the militants on Saturday in an bid to force them out of their area.

A top government official in Upper Dir, Atif-ur-Rehman, said the militia fighters had pushed the Taliban out of three villages and surrounded them in another two.

About 150 militants are believed to be there putting up resistance. But the villagers are doing well, they're squeezing the militants, Rehman told Reuters by telephone.

The United States, which needs sustained Pakistani action to help defeat al Qaeda and to cut off militant support for the Afghan Taliban, has been heartened by the resolve the government and military are showing in the Swat offensive.

Alarmed by the prospect of nuclear-armed Pakistan drifting into chaos, the United States had criticized a February pact with the Taliban in the former tourist valley of Swat.

The Swat offensive also has broad public support in a country where many people have long been suspicious of the United States and government critics have decried fighting America's war.

CLOSE QUARTERS

The February pact aimed at placating the Taliban in Swat by introducing Islamic sharia law sailed through parliament with only one or two voices of dissent.

But much has changed since then.

A Taliban push into a district 100 km (60 miles) from Islamabad, a widely circulated video of Taliban flogging a teenaged girl and the Islamists' denunciation of the constitution as unIslamic have sharply shifted public opinion.

The villagers' action in Upper Dir is the latest in a series of instances of people turning on the Taliban. Rehman said security forces could help the militia if necessary.

We don't want to step in right now as they're fighting at close quarters and there is a chance of losses on the villagers' side if we use artillery, he said.

While the government retains public support for the offensive, it could lose it if the 2.5 million people displaced by fighting in the northwest languish in misery.

The government is organizing relief with the help of the United Nations and other agencies but aid officials say Pakistan faces a long-term humanitarian crisis.

The military says it has snuffed out organized resistance in Swat and it hopes people can begin returning home after the middle of this month. On Monday, the military relaxed a curfew in areas near Swat to allow people to flee or shop for supplies.

Meanwhile, cities are on alert for bomb attacks.

Police in Karachi said on Sunday they had arrested an associate of Pakistani Taliban leader Baitullah Meshud and seized jackets to be used in suicide attacks. Police said the suspect had confessed to planning attacks.

(Additional reporting by Junaid Khan; Editing by Robert Birsel and Jeremy Laurence)