Hamdan, who had never seen his seven-year-old daughter until he was returned to Yemen, was taken to Guantanamo Bay in May 2002 after being picked up by US forces in Afghanistan.
He had already served more than five years in the US detention centre in Cuba when he was convicted in August and given credit for time served in the facility.
US prosecutors had argued that Hamdan should receive a custodial sentence of 30 years to life, but the military judge dismissed said he was just a "small player" in the al-Qaeda network.
Al-Ansi said that his client had served out the remaining time on his sentence and signed a pledge not to commit any violent acts.
About 100 of the 250 prisoners remaining at Guantanamo Bay are from Yemen, bin Laden's ancestral home.