The attack claimed by the al-Shabab extremist group occurred after the envoy to Somalia, James Swan, paid the mayor a "courtesy call" and left the compound, an official at the mayor's office told The Associated Press. The official spoke on condition of anonymity because they were not authorized to speak to the media.
The U.N. mission in Somalia in a tweet before the bombing posted photos of the smiling mayor and envoy, saying Swan had received an overview of the "challenges" in the region. The mayor, Abdirahman Omar Osman, and his deputy were rushed to a hospital with critical wounds, police Capt. Mohamed Hussein said.
Somalia's information minister Mohamed Abdi Hayir said six officials were killed and six others were wounded. He told reporters the mayor was being treated and gave no further details. He also confirmed an investigation was underway.
A Somali intelligence official said the officials killed included two district commissioners, two local government directors and a senior adviser to the mayor. The official spoke on condition of anonymity because they were not authorized to speak to the media.
U.N. Secretary-General Antonio Guterres strongly condemned "the deadly terrorist attacks" and reiterated the U.N.'s commitment "to supporting the people of Somalia in the pursuit of peace, stability and development," U.N. deputy spokesman Farhan Haq said.
It was not clear how the bomber managed to enter the mayor's office during a security meeting. Some security officials said the attacker might have coordinated with corrupt officials, offering them bribes for access.
The al-Qaida-linked al-Shabab often targets government buildings such as the presidential palace and other high-profile parts of Mogadishu with bombings. The security officials said Wednesday's attack appeared to be a shift in tactics, as the extremists in the past had rarely managed to infiltrate heavily fortified government buildings without first detonating one or more vehicle bombs.
The Somalia-based al-Shabab was chased out of Mogadishu years ago but still controls parts of the Horn of Africa nation's south and central regions and is a frequent target of U.S. airstrikes.
Follow Africa news at https://twitter.com/AP_Africa