Radical Sunni Islamist groups often target mosques frequented by minority Shi'ites, whom they see as infidels.
Police said armed men broke into the mosque, where people were attending Friday prayers, and opened fire, following which three explosions were heard inside the building.
The Pakistani Taliban, who are fighting against the state to set up a hardline Sunni theocracy, claimed responsibility and said the attack was revenge for Pakistan's crackdown on militants following a December school massacre.
"Either Pakistan will become your graveyard, or God's law, sharia, will be implemented," Taliban commander Khaleefa Omar Mansoor said in a video in which he was flanked by three young militants clutching AK-47 assault rifles.
"This is the first in a series of revenge attacks ... Wait for the rest," Mansoor, who had earlier claimed responsibility for the Dec. 16 school attack in which more than 150 people were killed, said in the video sent by email to reporters.
The style of the mosque attack was similar to that of the school attack, when gunmen arrived in a car, set it on fire, and broke into the building using a back entrance.
Peshawar's Hayatabad Medical Complex said at least 19 people had been killed in the latest attack.
A witness, Shahid Hussain, told Reuters the worshippers had just finished prayers when five or six men wearing military uniforms broke into the mosque and started shooting.
"We had no idea what was going on. One of the attackers then blew himself up and then there was huge smoke and dust all around," he said.
The attack came as Pakistan tries to adopt new measures to tackle militants following the school massacre, in which 134 children were among the dead.
The government has pledged to crack down on all militant groups, and has reintroduced the death penalty, set up military courts to speed convictions and widened its offensive in northwestern areas on the Afghan border where militants find refuge.
Yet Pakistan's religious minorities, among them Ahmadis, Christians and Hindus, say the government is doing little to alleviate their daily struggle against discrimination and violence.
Last month dozens of people were killed in a similar attack on a Shi'ite mosque in the southern town of Shikarpur.