Nasir Mahmood, the area's police chief, said the blast claimed 27 lives, including two police officers, and wounded 35 people.
"I can confirm that it was a suicide blast," Mahmood said.
Mohsin Shah, a senior district official, said the motive for the attack appeared to be sectarian, noting sectarian conflicts had spawned several targeted killings in recent weeks.
He said a Shia man shot earlier on Tuesday in the centre of the city was taken to the hospital where he died from the wound.
"Dozens of people from the Shia community had gathered at the hospital where the bomb went off," he said.
But Maulvi Umar, a spokesman for Pakistan's Taliban movement, claimed responsibility and said the mourners were not the target of the blast.
"What we are seeing is no change in the Pakistan government policies after Musharraf," Umar said, referring to ongoing military operations.
"We want the government to change its policies. This is not a sectarian attack. We take its responsibility."
A bombing in the main northwest city of Peshawar last week destroyed an air force truck and killed up to 14 people. The Pakistani Taliban claimed they staged it in response to recent military offensives.
More deaths in Bajur
On Tuesday, police said security forces backed by helicopters and artillery pounded fighters in the area, killing 11 suspected fighters and five civilians over a 24-hour period.
Government forces stepped up the shelling after a paramilitary post was attacked at Mamad Gatt near the Afghan border, said Fazal Rabbi, a police commander in Bajur.
He said he did not know if any of the paramilitary troops were killed.
Separately, government official Jamil Khan said 13 fighters and five paramilitary troops died on Tuesday in a clash at a fort in the Nawagai area of Bajur.
Also Tuesday, a man was killed and five others were wounded when two mortar shells hit two houses in separate incidents in the Matta area of the Swat Valley, another volatile northwestern region.