The attack marks the latest violence against a religious minority that has suffered repeated bombings and assassinations by hard-line Islamic militants. The violence also underscored the challenges the military and police face to secure the country two months after a horrific Taliban attack against a school sparked public outrage and cries for greater security.
The attack in the city of Peshawar wounded more than 45 people, according to Mian Mohammad Saeed, the chief of operations for the Peshawar police.
The Taliban claimed responsibility for the violence.
There were varying accounts of how many attackers carried out the assault. The militants released a video showing three attackers while the head of the provincial police, Nasir Durrani, said four or five attackers were involved.
The attackers entered the mosque from a building next door that was under construction, he said. They jumped over an outer wall into the mosque courtyard.
One person then blew himself up, creating a diversion so the other attackers could enter the mosque, Durrani said. He said at least three attackers died in the violence — two by blowing themselves up, and a third was killed by worshippers at the mosque.
"People here showed great courage. They grabbed one of the attackers from his neck, and he couldn't detonate (his explosives), and he was shot and killed," Durrani added.
Authorities were still examining the scene, and Durrani did not say what happened to any of the remaining attackers.
Some worshippers who fled the mosque reported that at least some of the attackers were wearing security uniforms.
"The prayer was about to end when a big bang happened, followed by dust and smoke. I have seen amid the smoke that one guy dressed in a police uniform was firing shots and then there was another blast," said one of the wounded, 22-year-old Syed Javed Hasan, speaking from his hospital bed.
One of the dead, Naveed Abbas, worked for the U.N. Department of Safety and Security, according to a statement released by the United Nations. Secretary-General Ban Ki-moon condemned the attack and urged Pakistani authorities, "to redouble their efforts to protect religious and ethnic monitories and to combat terrorism in all its forms," the statement said.
A spokesman for the Pakistani Taliban, Mohamad Khurasani, said the attack was in revenge for the execution of one of their members by the Pakistani government. This is the same group that claimed responsibility for a horrific attack on a school, also in Peshawar, on Dec. 16 that left 150 people dead, almost all of them students.
The violence horrified Pakistan and led to cries that more needed to be done to combat militants. The military stepped up operations in the rugged tribal areas bordering Afghanistan, and the government lifted a ban on executions in terrorism-related cases.
But despite these efforts attacks continue.
On Jan. 30, militants targeted a Shiite mosque in the southern city of Shikarpur, killing at least 59 people.
Sunni Muslim extremists often target Shiite religious pilgrims and places of worship because they do not considerShiites to be true Muslims. That has left many Shiites fearful for their own safety. In Peshawar, the imam of theShiite mosque that was attacked called on God to help protect his worshippers.
"This is very shameful and very sorrowful that people came to the mosque for worship and lost their lives instead," said Maulana Nazir Hussain, who said he lost his son and a nephew in the violence.
Associated Press writers Ishtiaq Mahsud in Dera Ismail Khan and Zarar Khan and Rebecca Santana in Islamabad contributed to this report.