The sailors, who had been held in dire conditions and suffered beatings and torture, included seven men from Bangladesh, one Indian, one Iranian, and two from Sri Lanka.
John Steed, a former British army colonel who helped negotiate their release, confirmed they had been freed.
"Currently airborne with hostages," Steed told AFP by text message.
Their boat, the Malaysian-flagged container ship MV Albedo was captured in November 2010 but sank in rough seas last July.
More From This Section
Seven other Pakistani crew members were released in 2012 after a businessman paid their ransom, but those remaining could not afford the hefty demands of the pirates.
"The crew members and their families have suffered unimaginable distress," United Nations special envoy to Somalia Nicholas Kay said in a statement.
"The crew underwent the trauma of piracy, their ship sinking, and then being held ashore in very difficult conditions."
Exact details of how they were released have not been given, but the United Nations said they had been handed over to their care, and "will be repatriated to their home countries over the coming days."
The sailors, like 38 others from different boats who remain hostage, were abandoned by their ship's owner whose willingness to pay to free them sank with their boat.
"While we have seen a significant reduction in piracy off the coast of Somalia in recent years, I remain deeply concerned that 38 other crew members are still being held hostage," Kay added.
Pirate attacks off Somalia have been slashed in recent years, with international fleets patrolling the Gulf of Aden and Indian Ocean, as well as armed guards being posted aboard many vessels.
"I call on those who continue to detain these crew members to release them without further delay so they can rejoin their families and loved ones," Kay said.