A suicide bomber from Somalia's Shabaab insurgents killed 18 police officers and wounded 15 others on Thursday when he blew himself up inside the country's main police academy, the force's chief said.
Witnesses said the police were gathered in a square ahead of their early morning parade when the bomber attacked in the capital Mogadishu.
"Eighteen members from the police were killed, and 15 others were wounded, after a suicide bomber blew himself inside the academy," acting police chief General Muktar Hussein Afrah told reporters.
The attacker disguised himself in a police uniform to access the camp, Afrah said.
"Some of the police were already in lines, and others were gathering, when the man in police uniform entered and blew himself up," said bystander Hussein Ali, describing the carnage.
Medics and ambulance teams rushed to take the wounded to hospital and collect the corpses.
Officers said the toll could have been far worse had the attacker killed himself in the centre of the crowd.
"The bomber could have inflicted more casualties if he could have managed to reach the midpoint where most people were," police officer Ibrahim Mohamed said.
The Al-Qaeda-affiliated Shabaab claimed responsibility and put the toll at 27 dead.
"It was martyrdom operation, in which the mujahedeen targeted the police academy camp," a statement posted on a pro-Shabaab website read.
Shabaab fighters have repeatedly attacked police officers in its decade-old battle to overthrow successive internationally-backed governments in Mogadishu.
The Shabaab lost its foothold in Mogadishu in 2011 but has continued its fight, launching regular attacks on military, government and civilian targets in the capital and elsewhere.