Militants stormed a Shiite mosque in northwestern Pakistan on Friday, killing 19 people in a wave of shooting and explosions before the siege ended, officials said.

The attack in the city of Peshawar also wounded more than 40 people, according to Provincial Information Minister Mushtaq Ghani. There was intense shooting in the immediate aftermath of the explosion he said, but the violence was now over.

The Taliban have claimed responsibility for the assault.

The head of the provincial police, Nasir Durrani, said four or five attackers entered the mosque from a building next door that was under construction, then 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 the remaining attacker or attackers.

Some people 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 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.

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.