World powers agreed plans in London to support and train Somalia's army and police to take over duties currently performed by the African Union.
But the country's president said unless a UN arms embargo was lifted the conflict would go on for 10 more years.
The UN secretary general said drought was Somalia's "most pressing priority".
UN chief Antonio Guterres called for an additional $900m (Â£700m) to allow aid agencies to tackle the severe drought facing the country, taking his total appeal to $1.5bn.
He added the conference at Lancaster House attended by more than 40 nations had created an opportunity to take Somalia out of "decades of conflict, of poverty and of terrible suffering".
Somalia's President Mohamed Abdullahi Mohamed, who took office in February, hailed it as a "historic day" for his country.
UK Foreign Secretary Boris Johnson, who co-hosted the conference, said by acting "early and decisively" the famine threatening Somalia could be avoided.
"For this to happen aid agencies must be free to go wherever necessary with safety and without hindrance to distribute food aid to all those in need," Mr Johnson said.
But he said it was not the time to lift the arms embargo because of fears weapons could end up in the wrong hands.
It has been in place since Somalia collapsed into civil war in the early 1990s.
Islamist group Al-Shabab, part of al-Qaeda, has a strong presence in many rural parts of Somalia and often stages attacks in the capital, Mogadishu, and elsewhere.
Opening the meeting, UK Prime Minister Theresa May said the "challenges that face Somalia affect us all".
She said: "If Somalia is a foothold for terrorist groups like al-Shabab and Daesh [the so-called Islamic State group], if global trade is hijacked by pirates or if millions are continually displaced in a desperate bid to escape poverty and drought, the impact of instability in Somalia is felt across the whole region and the wider world."
US defence secretary James Mattis, EU foreign affairs chief Federica Mogherini, the presidents of Kenya and Uganda, the prime ministers of Ethiopia and Turkey, and the foreign ministers of Egypt, Germany, the Netherlands and Qatar also attended the conference, the third such meeting on Somalia to be held in London since 2012.
Somalia has signed a security pact with the international community aimed at building a national force to fight al-Shabab militants.