"The Somali government welcomes the success attained by the Somali government forces backed by AMISOM (peacekeepers) who defeated the enemy of al-Shabaab," President Sheikh Sharif Sheikh Ahmed told a press conference, BBC reported.
Somalia has sunk into abyss over the deadly fighting between government troops and militants of Al-Qaeda-inspired Al-Shabab militants.
Over the past months, African Union peacekeepers and government forces have been contained to small areas of the capital.
Recently they have been battling the rebels in a bid to secure delivery routes for emergency supplies of food, water and medication.
Affected by war waged by al-Shabaab Islamists against transitional federal government and draught, more than 100,000 Somalis have fled from the lack of rain in their country to shelter in Dadaab refugee camp.
Government spokesman Abdirahman Omar Osman told Reuters the rebel pullout from Mogadishu was a "golden day" for Somalia.
"For the last (four) years Mogadishu has experienced atrocities at the hands of terrorists," Osman said.
“But today they are out.”
Somalia has lacked an effective government since the ouster of former president Mohamed Siad Barre in 1991.
More than 14 attempts to restore a functional government have since failed.
The UN agency says that the fighting has displaced over 23,000 people from the city over the past few weeks alone.
About 200,000 civilians are believed to have fled the continuing violence in Mogadishu thus far this year, the UN affirms.
The Qaeda-inspired group denied withdrawing from Mogadishu, describing the move as a "change of military tactics".
"We have abandoned Mogadishu but we remain in other towns," Sheikh Ali Mohamud Rage, al-Shabaab spokesman said on the al-Shabaab-run Andalus radio station, Reuters reported on Saturday.
Al Shabaab has never previously entirely abandoned Mogadishu during the course of a four-year insurgency that has killed tens of thousands of people.
Rage added that their troops would hold their positions elsewhere.
"We aren't leaving you, but we have changed our tactics," Rage said.
“Every one of you will feel the change in every corner and every street in Mogadishu. We will defend you and continue the fighting.”
Analysts believe it is too early to predict a better, calmer future for the war-torn capital.
“It seems very premature to be putting this down as a victory seeing that al-Shabab have vowed to fight on in Mogadishu but with different tactics,” Will Ross, BBC’s East Africa correspondent, wrote on the BBC.
“They say they are going to switch to guerrilla tactics, so we could now see more suicide bombings, more grenade attacks and perhaps the use of more landmines.”
“These kind of triumphant noises were made at the end of 2006 when the Islamists withdrew, only f