Scores more were wounded in one of the bloodiest attacks in a long series of assaults on the country's Shiite Muslim minority.
There was no claim of responsibility in the bomb attack, but Information Minister Sheikh Rashid Ahmed blamed "sectarian elements," an apparent reference to outlawed extremist groups of the Sunni Muslim majority, suspected in most of the previous attacks.
Accounts of the death toll varied. Emergency officials put the death toll at 47, but Ahmed said at least 30 died.
Shiite Muslims immediately took to the streets, setting fires and attacking buses and cars. Girding for more violence, the government called in troops to patrol the streets and imposed an indefinite curfew on the city of roughly 1.2 million people, about a third of them Shiites.
Authorities also stepped up protection around Sunni mosques and religious schools and ordered schools closed throughout Baluchistan province.
About 80 percent of Pakistan's 140 million people are Sunnis. Violent groups from both the Sunni and Shiite sects have sprung up in recent years.
The attack came on Friday, the day Muslims gather in their mosques for prayers and sermons. About 2,000 people were saying prayers at the time.
In the hours after the attack, confusion still surrounded the number of attackers and their fate.
Ahmed said there were three attackers — two killed in the mosque and another in a shootout with security guards outside. Other accounts said that there were two suicide bombers and two gunmen. They said one attacker was arrested.
Zulifquar Ali, a worshipper slightly wounded by shrapnel, said the assailants first targeted the mosque's security guards.
"First they killed security guards outside the mosque. Then they moved inside the mosque and started firing on the people," he told The Associated Press.
A security guard killed one attacker, Ali said.
"The other attacker blew himself up," he said.
The third attacker was seized by worshippers, their clothes soaked with blood. He was handed over to police.
Other witnesses said grenades were thrown into the mosque.
Ahmed said at least 30 people were killed and 52 were injured. But Allama Mahdi Najfi, the mosque's prayer leader, said after visiting victims in a hospital that the death toll was higher.
"Forty of our people have been martyred," Najfi said.
Najfi said blamed "those people who think the murder of Shiites is obligatory," an apparent reference to extreme Sunni Muslims.
The national private emergency service Edhi Foundation counted 47 bodies of mosque victims in hospitals, spokesman Mohammed Khalil said. The Edhi Foundation has emergency workers throughout Pakistan.
Hours after the blast, police found two bombs near the mosque's main wall. The bombs, which were defused, had been concealed in tin canisters, police official Abdul Hai said.
A group of Shiite youths angry over a shortage of doctors set fire to a hospital where victims were taken but the blaze was extinguished, Baluchistan Health Minister Hamid Ullah said.
Pakistan President Pervez Musharraf, in France on a state visit, pledged to "act very strongly" against those responsible for the mosque attack.
"It is unfortunate there are some elements in Pakistan who undermine what Pakistan stands for and for what the vast majority stands for," Musharraf said.
Musharraf has banned several militant Muslim groups in Pakistan, including extremist Sunni Muslim organizations blamed for earlier attacks on their Shiite brethren. Despite the ban, many of the groups' leaders still operate freely.
Nearly 2,500 Shiites staged a rally in Pakistan's central city of Multan to protest the attack. In a speech to the demonstrators local Shiite leader Tanveer Kazim accused Musharraf of ordering the attack.
Protesters responded by chanting slogans against the United States and Musharraf, a key ally in the U.S. war on terror.
Shiites were targeted twice last month in Quetta. On June 2, two gunmen riding motorcycles shot and killed a Shiite Muslim prayer leader, Syed Niaz Hussain.
On June 8, two gunmen, also riding motorcycles, killed 11 policemen, most of them Shiite Muslims. The attackers sprayed a truck full of policemen with machine-gun fire.
The Sunni-Shiite split in Islam dates back to a 7th century dispute over succession of authority after the death of the Prophet Muhammad.