A suicide bomber from Somalia's al-Shabab has killed 18 police officers and wounded 15 others after blowing himself up inside the country's main police academy, according to authorities.
Witnesses said the police were gathered on Thursday in a square before their early morning parade when the bomber attacked in the capital Mogadishu.
Al-Shabab, which is allied to al-Qaeda, 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-al-Shabab website read.
The assault is the latest in a decade-old battle by al-Shabab to overthrow Somalia's internationally backed government.
"Eighteen members from the police were killed, and 15 others were wounded, after a suicide bomber blew himself up inside the academy," General Muktar Hussein Afrah, acting police chief, said.
The attacker disguised himself in a police uniform to access the camp, Afrah said.
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 detonated his bomb in the centre of the crowd.
Later on Thursday, police attended the funerals of some of their colleagues killed in the attack.
In US crosshairs
Al-Shabab has become the deadliest group of its type in Africa and is increasingly targeted by the US military after the Trump administration early this year approved expanded air strikes and other efforts against the fighters.
The US has carried out at least 32 drone strikes this year.
Al-Shabab 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.
In October, a huge truck bombing blamed on the group killed as many as 512 people, levelling buildings in the capital's busy Kilometre 5 neighbourhood.
Since then the US has increased the frequency of air strikes targeting al-Shabab leaders.
A strike earlier this week against an al-Shabab vehicle carrying explosives prevented an "imminent threat to the people of Mogadishu", the US Africa Command said.
An operation against an al-Shabab camp on November 21 killed more than 100 fighters, according to the US Africa Command.
On November 13, the Pentagon said US forces had killed more than 40 al-Shabab and ISIL fighters over four days.
The increase in US raids comes as AMISOM, the AU's mission in Somalia, prepares to withdraw 1,000 troops from its 22,000-strong force, as part of plans to pull out all soldiers by December 2020.
The US is worried the reduction will hamper efforts against armed groups in the Horn of Africa.
A UN report last month warned that an ISIL faction in the north of the country had grown significantly over the past year, carrying out attacks in the Puntland region and receiving some funding from Syria and Iraq.