The UK is the first European Union country to reopen an embassy in the country since the Federal Government of Somalia was established last year.
Mr Hague said Somalia had been through a “dramatic shift”, but continues to face “huge challenges”.
The prime minister will host a Somalia Conference in London on 7 May.
The conference, which will be co-hosted by Somali President Hassan Sheikh Mohamud, aims to provide co-ordinated international support for the new government as it rebuilds the country after two decades of conflict.
‘No illusions’
Speaking from the new embassy site, the foreign secretary said: “We should be under no illusions as to the sustained efforts that will be required, in Somalia and from its international partners, to ensure that Somalia continues to make progress.”
Continue reading the main story
Analysis
Anne SoyBBC News
A faded, evidently old flag is hoisted above the newly opened British Embassy in Mogadishu. Then it is lowered and a newer, brighter flag goes up the mast. The union jack is back in the city after 22 years.
Somalia’s president Hassan Sheikh Mohamoud describes this event as a significant step for his country.
British foreign secretary William Hague re-opened the embassy in Mogadishu, signalling the rekindling of more solid ties between the two countries. “We will help bring development needed for long-term peace and prosperity,” says Mr. Hague.
A look around the embassy tells the story of a country ravaged by years of civil war.
The embassy is actually six shipping containers customised to serve as offices. Tonnes of sand-filled blast-proof fencing surround the area. It is the first European embassy to return to the Horn of Africa country. Mogadishu is slowly recovering.
He said the opening of the embassy was “testament” to the strength of the UK/Somalia bilateral relationship.
“We will continue to work closely with the Somalia government on shared priorities, which include tackling conflict, countering terrorism and piracy, providing humanitarian assistance, and promoting UK interests in Somalia,” he added.
Accompanied by the president, the foreign secretary opened the core office of the new embassy at Mogadishu International Airport with a short ceremony and flag-raising.
British Ambassador Matt Baugh, who had been working from Nairobi in Kenya because of security concerns, will move into the office, but the rest of the embassy compound is not expected to be completed until the end of July.
The former British embassy, located close to the port, was closed in January 1991 following the overthrow of the government, and the building is now a ruin.
During his visit to Mogadishu, Mr Hague also met with representatives of Somali civil society to discuss the prevention of sexual violence.
Mr Hague is leading efforts amongst G8 foreign ministers to tackle sexual violence in conflict and has announced £10m of fresh UK funding to support efforts against it.