Britain will contribute to a £50 million fund to improve security in Somalia, David Cameron has said.
Speaking after an international conference in London on Tuesday aimed at bolstering support for the troubled African nation, the prime minister said there had been "remarkable" progress since the first meeting last year but warned that "huge challenges" remain.
Mr Cameron said radicalism was "poisoning young Somali minds" which posed a threat to UK security.
"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."
Britain and a number of nations including China, America and South Africa, have agreed to contribute to the £50m funding pot that will back plans to build up the army, police force and strengthen maritime security.
The UK agreed to provide military expertise and a two-year £10m boost to the Somalian army in its fight against the al Shabaab Islamist militias, so long as it tackles human rights and financial management concerns.
Another £14.5m will be directed to rebuilding prisons and adding 250 new places, doubling police numbers to nearly 12,000 and setting up mobile courts to cover refugee camps and remote districts.
Other elements of the help agreed on security and governance are £2.6m to pay public officials and expert advice on accounting and financial reporting, £1.5m in anti-piracy measures.
Around half a million Somalis are expected to benefit from a £145m boost to humanitarian aid and a team of UN experts in ending violence against women is being deployed to Somalia this summer.
The conference brought together more than 50 governments and global bodies such as the IMF to hear Somali president Hassan Sheikh Mohamud outline his plans to stabilise the country after two decades of brutal civil war.
He is leading the country's first widely-recognised government for more than 20 years and there has been progress in extending its influence beyond the capital Mogadishu, which is starting to show signs of economic recovery despite continued terror attacks.
Mr Cameron said attendees were united around the plans set out by the president, who he said faced "one of the most difficult tasks of any leader anywhere in the world", and that the United Nations was making its "deepest involvement" in the country for more than 20 years.
Stood alongside him at a press conference, the Prime Minister said: "This is not just vital for Somalia; it is vital for Britain, for our national security and for the security of our allies all around the world."
"Today the international community has taken major steps to back the new president of Somalia with his plans for long-term security, for transparent and accountable government and for building a fully-federal government in which everyone has a stake and a voice."
The plans "offer a fundamental break with the corruption of the past", helping attract investment and allowing global financial institutions - as the World Bank has already - to help Somalia deal with its debts.
President Mohamud said his goal was a united and stable Somalia - he is aiming for national elections in 2016 - and that the level of international support at the conference was "very, very encouraging".
"The world has a partner it can trust. We are working hard to reform our country.
"We have been given a chance and we will prove in the eyes of the world that we will deliver.
"We cannot afford to miss this golden opportunity and we hope the world's support and commitment will be materialised soon."