A suicide bomber blew himself up at the entrance to a busy market in the main town of northwest Pakistan's Swat district on Saturday, killing three people and wounding 12 others, the military said.
Two bombers tried to launch the attack in Mingora, but police said security forces shot dead one before he could detonate his explosives.
"It was a suicide attack," Qazi Jamil, the police chief for the northwestern Malakand region to which Swat belongs, told AFP in a message.
"One was shot dead while the other exploded himself," he said.
Police said that a gunfight also took place before the suicide attack.
"We arrested three militants from a car in the morning, other militants hiding somewhere in the market started firing on security forces, injuring two paramilitary personnel," Jamil told AFP, adding that troops returned fire and arrested another militant who was wounded in the firefight.
After the shooting, troops began a search operation and tried to arrest the two would-be suicide bombers in the nearby market, but one managed to detonate his suicide vest after his companion was shot dead by troops.
Eight shops were also badly damaged in the blast, Jamil added.
Major General Ashfaq Nadeem, the operational head of Pakistani troops in Swat said that a total of four militants were killed during the shootout and suicide attack.
"There were four hardcore militants involved in today incident, one blow himself up while three others were killed in the encounter. Three civilians were also martyred in the suicide attack," he told reporters in Mingora, the main town of Swat valley, about 125 kilometres (80 miles) northwest of Islamabad.
Seven troops and five civilians were also wounded in the gunfight and suicide attack, he added.
"Today we have flushed out a group involved in such type of attacks. I think the mastermind was also eliminated," he said.
For two years the Taliban paralysed much of the Swat valley by promoting a repressive brand of Islamic law, opposing secular girls' education and beheading opponents, until the government ordered in thousands of troops.
Following a major military offensive launched last April in the districts of Buner, Lower Dir and then Swat, Pakistan declared that the mountain region was back under army control last May.
Many of the estimated two million people who fled have now returned to their homes in and around Swat and are trying to rebuild their lives, but skirmishes, threats and tensions have remained.
Saturday's bomb was the first in Mingora since a suicide attacker killed nine people in the city on February 22.
Suicide and bomb attacks blamed on Taliban and Al-Qaeda-linked militants have killed nearly 3,300 people since July 2007 across nuclear-armed Pakistan, and last year killed more civilians than in war-ravaged Afghanistan.
In southwestern Pakistan, which is also troubled by Islamist militants, separatist unrest and sectarian violence, a tricycle bomb exploded in the main city of Quetta, wounding six people, officials said.
The remote-controlled bomb exploded when a police van passed by in the Saryab neighbourhood, police said.
Four policemen and two pedestrians were among the injured, they added.
Quetta is the capital of oil and gas-rich Baluchistan province, which borders Iran and Afghanistan.
There was no immediate claim of responsibility, but similar bombings have been blamed on separatist, secular tribal rebels in Baluchistan.
In another incident, a remote control low intensity bomb blast late Friday wounded three people in Karachi, the economic hub of Pakistan, police said.

Copyright 2010 AFP South Asian Edition