A suicide bomber killed 38 people on Thursday and wounded more than 50 others, most of them Pakistani policemen, attending a funeral on the eve of the Eid al-Fitr Muslim festival, an officer said.
The attack at police headquarters in the southwestern city of Quetta was the latest in a series of attacks highlighting the major security challenges faced by a newly elected government.
The bomber struck as officers gathered to pay their respects to a colleague who had been shot dead only hours before in Quetta, capital of the troubled province of Baluchistan.
Fayaz Sumbal, a deputy inspector general of police and one of the most senior officers in Quetta, was among those killed.
"At least 38 people have been killed and more than 50 injured," senior police official Mohammad Tariq told AFP. "Most of the dead and injured are policemen."
A son of the imam of the mosque at the police headquarters was among the dead, Doctor Syed Sarwar Shah told AFP at one hospital.
There was no immediate claim of responsibility. Quetta sits on the frontline of Islamist militant violence, a Baluch separatist insurgency and violence targeting the Shiite Muslim minority.
Police officer Rahim Khan had earlier put the death toll at 28 but warned that many of the injured were in a critical condition.
Police said the attack was carried out by a suicide bomber.
Witnesses described the horror after the explosion.
"I was inside the mosque and we were lining up for the funeral prayers when a big blast took place. I came out and saw injured and dead bodies lying on the ground," policeman Mohammad Hafiz told reporters.
"I have no words to explain what I've seen. It was horrible."
Another witness told reporters he saw dead bodies scattered everywhere.
"Most of the bodies were beyond recognition. We collected body parts and flesh," he said in the interview broadcast by TV channel ARY.
"Those who are killing people, even inside mosques, are not human beings, they are beasts. They are not Muslims, they have nothing to do with Islam. Allah will never pardon them," he added.
The blast capped a bloody Ramadan in Pakistan, where at least 11 attacks have killed more than 120 people during the fasting month which is one of the holiest times in the Islamic calendar.
The month ends with the festival of Eid.
Early Wednesday a bomb killed eight people at the end of a football tournament in Pakistan's biggest city Karachi, many of them young fans watching the game from the stands.
On Tuesday Baluch separatist gunmen shot dead 14 people, including three security officials, 70 kilometres (44 miles) southeast of Quetta.
Pakistan is also in dispute with India over the killing of five Indian soldiers in the disputed Kashmir region this week.
On Thursday the Indian government for the first time directly accused Pakistan's army of involvement in the deadly ambush.
Defence Minister AK Antony warned the ambush would damage warming ties with Islamabad, and hinted at stronger military action along the Line of Control which divides Kashmir into Indian and Pakistani sectors.
Pakistan denies involvement in the killing.