The UN office for Somalia is moving to Mogadishu from Nairobi, UN head Ban Ki-moon has announced on a rare visit to the Somali capital.
The UN secretary general is the highest-ranking foreign official to visit the war-torn city for many years.
He was wearing a bulletproof vest as he was welcomed at the airport by Somalia's prime minister.
Islamist militants are battling the forces of the UN-backed government and African Union troops.
Somalia has been convulsed by war for two decades and has not had a functioning national government since 1991.
Mr Ban's visit comes a day after the fiercest clashes in the city for several months.
All major roads in the city were closed and flights in and out of Mogadishu were cancelled for security reasons.
Mr Ban was expected to discuss the political situation in Somalia, as well as the famine, which as been declared in some southern areas following a severe drought.
The BBC's Barbara Plett, who is travelling with Mr Ban, says he raced through the city's quiet streets to the presidential palace in a convoy of armoured personnel carriers.
Militant group al-Shabab said in August that it was pulling out of Mogadishu but it has since staged several attacks on the city and Mr Ban's visit was kept secret until after his arrival.
Al-Shabab, which has links with al-Qaeda, controls many southern and central areas of the country.
Some donors accuse the government of spending too much time squabbling and not enough time improving the lives of ordinary people.
The UN Security Council has said it will withdraw funding unless there are serious effort to meet an August 2012 deadline to draw up a political roadmap, which should lead to elections for a new president and parliament next year.
The government has long demanded that the UN office move into the country and this announcement is seen as very important, our correspondent says.
"I believe Somalia is at a critical juncture, a moment of fresh opportunities," Mr Ban told a news conference at Mogadishu's presidential palace.
He welcomed Kenya's decision to incorporate its troops into the African Union mission in Mogadishu, bolstering the 9,000 soldiers from Uganda and Burundi.
Kenya sent troops into Somalia in October, accusing al-Shabab of abducting foreigners from its territory - charges denied by the militants.
While UN officials insist that the security situation has improved, Mr Ban's convoy drove past the site of a suicide bombing earlier this week, which left at least five people dead.
Officials say there is an average of eight bombing incidents a day - both those which are defused and those which go off - so our correspondent says it is clear that the progress remains fragile.
Mr Ban later travelled to the world's biggest refugee camp in Dadaab, across the border in Kenya, where many thousands of Somalis have fled.
For security reasons he did not enter the camp but remained in a UN compound where he met some elders and refugees.
Although some southern areas of Somalia are no longer classified as famine zones, aid workers say Somalia remains the world's worst humanitarian situation.
Al-Shabab prevents most Western aid agencies, including the UN, from working in areas they control, accusing them of having a political agenda - a move Mr Ban condemned.