The president left Mogadishu airport, the base for 1,200 African Union troops that have just arrived from Uganda and the target of recent mortar attacks, immediately after his arrival.
The Somali interim government voted overwhelmingly on Monday to relocate from the provincial town of Baidoa to Mogadishu, where fighters have stepped up guerrilla-style attacks in recent weeks, killing dozens of civilians.
But longer term the move will depend on the government's ability to restore stability there.
Salad Jelle, the deputy defence minister, said on Tuesday: "The president's office will be fully operational in Mogadishu from today and all other ministers and government officials will follow suit.
"Every minister will set up his offices in the capital," he said.
"From what you see on the ground, Ethiopian and Somali troops are at every junction, so the president can safely get to Villa Somalia [the presidential residence]," Jelle said.
"Islam is as responsible as Christianity for wars that took place. History teaches us that religion has to be contained as 'private'."
Justice, Shenzhen, China
Send us your views
So far, attacks have continued, with Mogadishu residents on Monday reporting at least one dead and five injured after a gun battle sparked by an attack on Ethiopian forces.
The shelling of the presidential palace is the latest in a string of attacks since January when joint Ethiopian-Somali forces ousted the powerful Union of Islamic Courts movement from the country's southern and central regions.
The six-month AU mission aims to deploy about 8,000 troops to enable Ethiopian forces to leave and Somali forces to take over security.