President Mohamed Abdullahi Mohamed named current information minister Abdirahman Omar Osman to the post of Mogadishu mayor and governor of the Banadir administration, the region that includes the city, according to a statement from his office.
Osman replaces Thabit Abdi Mohamed who has served just nine months in office.
Immediately after the mayor's firing, government security forces were deployed across Mogadishu to forestall any potential protest against the move.
Earlier, Mohamed's supporters in the city council had nominated him to head an autonomous Banadir administration, hoping to secure for the city and surrounding area equal status to Somalia's six regional states, which have their own presidents and enjoy a greater degree of autonomy.
The central government is opposed to any such efforts.
The row started earlier this month when the mayor called for a conference to discuss the future status of Banadir region, against the will of the president, who is better known by his nickname Farmajo.