Somalia’s President Hassan Sheikh Mohamud says Somalia has entered a new era that will herald the end of more than two decades of conflict.
He was speaking at a major international conference in London to help Somalia rebuild itself.
The UK and other donors pledged some $130m (£84m) in aid for Somalia.
UK Prime Minister David Cameron said huge progress was being made in curbing piracy and tackling an Islamist insurgency in Somalia.
Somalia is widely regarded as a failed state, hit by numerous conflicts since the overthrow of long-serving ruler Siad Barre in 1991.
The United Nations (UN) estimates that nearly 260,000 people died during a famine in the East African state from 2010 to 2012.
Al-Shabab, which is linked to al-Qaeda, still controls much of the country.
The government depends on about 18,000 African Union (AU) troops to stay in power.
Mr Cameron said UK security was threatened by radicalism that was “poisoning young Somali minds”.
“If we ignore it we will be making the same mistakes in Somalia that we made in Afghanistan in the 1990s. I’m not prepared to let that happen,” Mr Cameron said.
Mr Mohamud said there had been a paradigm shift in Somalia since his government took office last year.
“Soon, Somalia will be a different place, a better place,” he said.
Mr Mohamud was chosen by MPs in September 2012.
Mr Cameron said the UK and other countries – including China, the US and South Africa – had agreed to contribute £50m ($77m) to help Somalia rebuild its security forces so they could tackle insurgents and criminal networks.
The European Union said it had pledged $58m towards the initiative.
“In Somalia, like anywhere else, there can be no development without security,” it said in a statement.
The meeting follows similar conferences in London and the Turkish city of Istanbul last year, amid growing international concern that Somalia had turned into a haven for al-Qaeda-linked militants.
The new government is the first one in more than two decades to be recognised by the US, the International Monetary Fund (IMF) and other key players who are attending the conference.
In a BBC interview, Mr Cameron said Somalia was “one of the most broken countries in the world” and the “writ of the government, as it stands today, doesn’t run a long way outside Mogadishu, but at least it has a government, it’s making a start and I think we’re seeing some real progress”.
Mr Cameron also held talks with Kenya’s President Uhuru Kenyatta, who is attending the conference – his first visit to a Western country since his election in March.
The UK had said it would have limited contact with him, as he been charged by the International Criminal Court (ICC) with crimes against humanity over his alleged role in fuelling violence after the disputed 2007 election – charges he denies.
Mr Cameron defended meeting Mr Kenyatta, saying he was co-operating with the ICC and Kenya was playing a vital role, along with other regional states, to beat back al-Shabab in Somalia.
The leaders of Ethiopia and Uganda, which have troops in Somalia fighting al-Shabab, were also at the conference.
Mr Mohamud told the BBC that he envisaged the withdrawal of the AU force within two years.
BBC Somalia analyst Mary Harper says Mr Mohamud’s estimate appears to be optimistic, as he is little more than the president of the capital, Mogadishu.
The Somali army is made up of clan militias with questionable loyalty, she says.
Somalia is also divided into a patchwork of self-governing regions, many of them hostile to the central government.
The breakaway state of Somaliland and the semi-autonomous region of Puntland have boycotted the conference.
Somalia’s government is also totally dependent on foreign aid, and has so far refused to agree to set up a joint oversight mechanism to curb corruption, our correspondent says.
But Mr Cameron told the BBC the government had “signed up to an awful lot of new measures” to ensure that it accounted for aid money.
He added that “huge progress” was being made in Somalia.
Piracy was down by 80% this year with no vessel attacked so far, Mr Cameron said.
However, the World Bank estimated in a report in April report that piracy emanating from the Horn of Africa nation may still cost the world economy $18bn a year, he added.
“Britain will also support the new maritime strategy enabling full radio connection all along the entire coastline for the first time in 20 years,” Mr Cameron said.