The blast damaged several small shops and peppered a wall with shrapnel, leaving scores of pockmarks, according to local TV footage. Ambulances rushed in to pick up the dead and wounded, as police tried to keep back onlookers in the crowded bazaar.
The explosion killed 23 and wounded over 50 people, said another police officer, Naeem Khan. One policeman who was guarding the mosque was killed and another was injured. Most of the dead and wounded were Shiites, but some of the casualties were also from the country's majority sect since there is a Sunni mosque nearby, said Khan.
Ahsan, the Pakistani Taliban spokesman, claimed responsibility for the attack and said they were targeting Shiites.
The worst sectarian violence in Pakistan in recent years has been in southwestern Baluchistan province, which has the largest concentration of Shiites in the country. A twin bombing last month at a billiards hall in the provincial capital, Quetta, killed 86 people, most of them Shiites.
According to Human Rights Watch, more than 400 Shiites were killed in targeted attacks in Pakistan in 2012, including over 120 in Baluchistan.
Sectarian militant groups, such as Lashkar-e-Jhangvi, have increased their strength through alliances with al-Qaida and the Pakistani Taliban, which has been waging a bloody insurgency against the government for the past several years.
Rights organizations have criticized the Pakistani government for not doing enough to crack down on the attacks against Shiites.
Pakistan's intelligence agencies helped nurture Sunni militant groups like Lashkar-e-Jhangvi in the 1980s, to counter a perceived threat from neighboring Iran, which is mostly Shiite. Pakistan banned Lashkar-e-Jhangvi in 2001, but the group continues to operate fairly freely.
Associated Press writers Hussain Afzal in Parachinar, Pakistan, and Zarar Khan in Islamabad contributed to this report.