William Hague has called for a stepping up of the fight against Somali-based terrorism as he became the first British foreign secretary to visit the war-torn state for 20 years.
His arrival in the capital Mogadishu amid tight security marked the start of a major diplomatic push to bring stability to a country he described as "the world's most failed state".
Mr Hague said recent gains by the 10,000-strong African Union force in the country (Amisom) had driven back the radical Islamist group al Shabaab from the capital. But with much of the south of the country still controlled by the organisation, which has links to al Qaida, he said there must be no let-up in the pressure.
Britain is hosting a major conference on Somalia in London later this month, attended by representatives of 50 nations in international organisations. Mr Hague promised that counter-terrorism would be high on the agenda as well as tackling piracy and Somalia's deep humanitarian problems.
"One of the objectives of our conference in London is to strengthen counter-terrorism co-operation to make it easier for countries in this region to disrupt terrorist networks, to disrupt their financing and the movement of potential terrorists," he said.
In 2010, MI5 director-general Jonathan Evans warned it was "only a matter of time" before terrorists trained in Somali camps inspired acts of violence on the streets of the UK. However, ministers believe the success of the Amisom offensive last August in driving al Shabaab from Mogadishu has opened up a window of opportunity.
At his meeting with Somali president Sheikh Sharif Sheikh Ahmed, Mr Hague announced the appointment of Matt Baugh as Britain's first ambassador to the country since it collapsed into chaos and civil war in 1991. He also confirmed his intention to establish a new British embassy in Mogadishu once the security situation allows.
For now, however, with suicide bombings, improvised explosive devices and grenade attacks still a regular occurrence, Mr Baugh will work out of the British High Commission in neighbouring Kenya.
The volatile security situation meant that Mr Hague's 10-minute drive from the Amisom base at the city's airport to the presidential residence at Villa Somalia had to be made in a small fleet of heavily protected armoured vehicles.
The route took him past shops and buildings bearing the scars of two decades of conflict, including the country's bombed-out parliament building. However, observers in the city say there are new signs of life emerging from the rubble since Amisom's August offensive, with businesses opening up, buildings being repaired and people and traffic returning to the streets.