Abdifatah Barre, the deputy district commissioner of Mogadishu's Wadajir district, was shot dead in his car, Reuters said.
"Gunmen opened fire on the car of the deputy district commissioner this morning. The official died and the gunmen escaped," Major Ibrahim Hussein, a police officer, said.
Shabaab, linked to terror group al-Qaeda, claimed responsibility and said more attacks would occur.
"We killed the deputy district commissioner and we shall continue killing the enemies. This is part of our operation in Mogadishu," Sheikh Abdiasis Abu Musab, its military operations spokesman, said.
The killing took place one month after the militants attacked a university college in Garissa, Kenya, killing 148 people.
Al-Shabaab aims to overthrow the current Somali regime and end what the group perceives as an unjust occupation of Somali land by Kenyan troops, deployed in 2011.
The insurgents often carry out attacks in neighbouring Kenya killing dozens of people and negatively impacting local tourism, a big source of income for the country.