The state department said the “historic event” reflected the progress the east African nation had made.
Ambassador Donald Yamamoto is heading the embassy in Mogadishu. Previously it had been based in Nairobi, Kenya.
The US closed its embassy in Somalia in January 1991 amid fighting between rebels and the government and had to airlift out its ambassador and staff.
Commenting on the latest move, state department spokeswoman Heather Nauert said in a statement: “This historic event reflects Somalia’s progress in recent years and is another step forward in formalising US diplomatic engagement in Mogadishu since recognising the Federal Government of Somalia in 2013.”
She added: “Our return demonstrates the United States’ commitment to further advance stability, democracy and economic development that are in the interest of both nations.”
Security has improved in Mogadishu recently, although al-Shabab rebels remain a threat.
Al-Shabab was forced out of the capital in August 2011 following an offensive spearheaded by African Union troops.
But it still has a strong presence in regions around the capital.
US President Donald Trump expanded operations against al-Shabab in March 2017 and the US military has conducted more than two dozen air strikes, including drone strikes, in Somalia this year,
Traditionally, US presidents have been wary of intervening in Somalia since 18 special forces soldiers died fighting militias in Mogadishu in 1993, a battle dramatised in the film Black Hawk Down.
Last month, the US announced it was cutting 700 counter-terrorism troops from Afrika over the next few years, although its activities in Somalia will remain largely the same.