Mohamed Ali Abukar - a Somali working for the UN Development Programme - was said to be tired but unharmed.
Mr Abukar was the second UN official to be abducted by gunmen in Mogadishu this year.
After he was seized by armed men on 28 April, the UN suspended all its activities in the Somali capital.
Since Somalia descended into clan warfare following the overthrow of Mohamed Siad Barre in 1991, abductions have been used by gunmen to extract ransom money.
Hostile environment
However family members said no money had been paid for Mr Abukar who was released early on Saturday morning, according to the French news agency AFP.
In the earlier kidnapping in February, a Somali representative of the UN children's fund (Unicef) was picked up by unidentified gunmen and released later.
In a report published earlier this year, UN Secretary-General Kofi Annan said Somalia remained one of the most dangerous environments in which the UN operates, and that the security situation did not allow for a long-term presence.
Last year, the UN withdrew international staff from Mogadishu after insurance companies refuse to insure flights in the wake of the 11 September attacks.