The blast happened in Mingora, the main town of Swat district where 2,500 paramilitary troops were deployed this week to fight supporters of a militant cleric. It set off an explosion of ammunition carried inside a military truck, triggering bullet fire.
Amjad Khan, a police officer dispatched to the hospital where the casualties were taken, said a suicide bomber killed at least 19 people and wounded 29. Most of the casualties were soldiers, but some bystanders were also hit. Some nearby shops, restaurants and cars were damaged.
Khan said the bomber hit a platoon of Frontier Constabulary troops in the truck about 300 yards from police district headquarters.
However, Fazlur Rehman, the top local official at the scene, said some 45 troops were inside the truck and the devastation of the wreckage, which took firefighters several hours to extinguish, showed that all must have died. Three passers-by were also killed, he said.
Rehman also said an engine of another vehicle was found near the truck, showing it was a car bomb.
Mohammed Sajid, a citizen who helped some of the wounded from the truck, said there were as many as 20 dead.
Ambulances raced to the scene and authorities were calling for blood donations for the wounded.
Taj Mohammed Khan, 23, a college student who was drinking tea at a nearby roadside restaurant, said the truck caught fire after the explosion and then bullets went off.
"It was a huge explosion. Then the truck was on fire. There were flames, smoke and people crying. People were scared to go near because bullets were going off," he said. "Some people were injured in the restaurants and several cars were also damaged."
Police said it was suicide attack.
There was no immediate claim of responsibility.
Pakistan's army said Wednesday that new troops have been deployed to Swat, a mountain valley popular with tourists until violence flared there this summer, to quell Maulana Fazlullah, who has called for Taliban-style rule and holy war against Pakistani authorities.
The once idyllic valley has seen a string of bombings and suicide attacks on security forces - part of a wave of violence that has undermined the government's control of a swath of territory along the northwestern border, where sympathizers of Taliban and al Qaeda hold sway.
A spokesman for Fazlullah denied involvement in the bombing.
"We want peace in Swat," spokesman Sirajuddin, who goes by one name, told The Associated Press by phone. "We have been working against criminals here, against murderers, abductors and wine drinkers ... we have given them punishment. Some of them are still in our custody."
"There is absolutely no need for the army here," he said. "This happens when the army comes here. This has happened in the past," he said referring to attacks on security forces.
Two suicide attackers and a roadside bomb simultaneously struck a military convoy in Swat, killing 11 soldiers and three civilians, after a deployment in July.
Late Wednesday, Fazlullah announced in a pirate FM radio broadcast that he was leaving his headquarters in the Swat district for the neighboring mountain area of Kohistan.
Iqbal Hussain, a Mingora businessman who heard the broadcast, said Fazlullah warned the government not to carry out any military operations, saying if a single bullet were fired, the door for negotiations would close and the government would be responsible for the deterioration in the situation.
Fazlullah is the leader of Tehrik Nifaz-e-Sharia Mohammed, TNSM a banned pro-Taliban militant group which sent thousands of volunteers to Afghanistan to during the U.S.-led invasion in 2001.
As well as marshaling armed militants and enforcing Islamic law, Fazlullah has used an FM radio station to campaign against girls' education and denounce a recent polio vaccination program as a Western plot to sterilize Muslim children.