The government plans to appeal against the High Court decision
An asylum seeker who was threatened with deportation to Iraq before being cleared of terrorism-related offences has won a false imprisonment claim.
The man, 30, identified only as HXA, sued the Home Office over his detention from 26 January to 23 November 2005.
Mr Justice King told the High Court his detention at the hands of the UK government was "unlawful throughout".
The damages sum will be assessed at a later date, unless the government wins its planned appeal.
The judge had been told that, after arriving clandestinely by lorry in the UK in July 2000, HXA's asylum application was refused but that he was granted exceptional leave to remain until October 2005.
In January 2005, he was told he faced deportation for national security reasons on grounds he had supported the anti-coalition insurgency in Iraq, having travelled there in 2004.
He was also said to be in contact with individuals in the UK assessed to be operating to an al-Qaeda agenda.
In February 2005, HXA appealed to the Special Immigration Appeals Commission and, in November, was released from detention when the Home Office withdrew the decision to make a deportation order.
However, he was immediately re-arrested by the police on suspicion of having committed offences under the Terrorism Act before being acquitted of all charges in August 2006.
He was then made subject of a control order - which imposes electronic tags, movement restrictions, curfews and monitoring - which is also the subject of a court case.
His counsel, Stephanie Harrison, told the judge that he had been held illegally because no lawful decision to make a deportation order had been made at the outset.
The Home Office claimed the decision to deport was made properly and in good faith for reasons of national security and that it was entitled to detain HXA pending the deportation order being imposed.
The judge ruled that detention was illegal because no proper consideration had originally been given to the question of what would happen to HXA on his return to Iraq or to meeting the requirements of the European Convention on Human Rights.