The bomber struck as some 300 people, including top police officers of Balochistan province, were attending the funeral of police station chief Mohib Ullah, who was gunned down this morning.
The attacker detonated his explosive vest when he was stopped by guards at the gate of a mosque within the Police Lines in Quetta, the capital of Balochistan.
"It was a suicide attack and the attacker blew himself up at the entrance where he was intercepted by policemen on duty," city police chief Mir Zubair Mehmood said.
Senior police officials said 38 people were killed and 50 others, mostly policemen, injured.
Deputy Inspector General of Police Fayyaz Sumbol, Superintendent of Police Ali Mahar and Deputy Superintendent of Police Shams–ur-Rehman were among the dead. Balochistan police chief Mushtaq Sukhera said 21 policemen died in the attack.
"It is a major attack on police and at least eight kilograms of explosives were used in the suicide attack," Mehmood said.
The provincial police chief and city police chief had a narrow escape. The bomber carried out the strike despite extensive security arrangements within the Police Lines.
The victims were taken to a military hospital due to fears that civilian hospitals might be attacked. After a recent bombing at a women's university in Quetta, militants attacked the hospital where the injured were taken.
The number of casualties in the attack is expected to rise as some of the injured were critical, doctors said.
Earlier in the day, police station chief Mohib Ullah was killed and his four children and a driver were injured when unidentified gunmen attacked his car at Alamu Chowk in Quetta.
Mohib Ullah was going to the market with his children when he was attacked.
No group claimed responsibility for both attacks. Several militant groups, including the Taliban and Lashkar-e-Jhangvi, are active in Balochistan.