Ordering his release on Monday, Richard Leon, a US district court judge, said the government's claims made no sense and emphatically rejected the case.

"I disagree!" he wrote, adding that US officials are "taking a position that defies common sense".

Leon also said the government and the US media initially mistook Rassak as one of a number of would-be suicide bombers based on videotapes captured at an al-Qaeda safe house.

But further investigations showed that the tapes actually showed al-Qaeda members torturing him.

In a 13-page written decision, the judge criticised the suggestion that Rassak could be part of the same organisation that had abused him.

'No evidence'

"There is no evidence - from either side - as to why he suddenly was suspected by al-Qaeda leaders of spying and was tortured for months into giving a false confession," Leon wrote.

"It is highly unlikely that by that point in time al-Qaeda [or the Taliban] had any trust or confidence in him. Surely extreme treatment of that nature evinces a total evisceration of whatever relationship might have existed!"

Steven Wax, one of Rassak's lawyers, said the judge's decision "is yet another reminder that there are innocent men in Guantanamo".

There are currently 229 detainees still held at the US military base in Guantanamo Bay, Cuba.

Barack Obama, the US president, has ordered the detention centre closed by early next year.