European human rights judges have ordered the Government to pay more than £13,000 to an Iranian offender.
The man was awarded the sum after complaining about the length of time he was held in immigration detention following the completion of his sentence for indecent assault.
Named as J.N. in court documents, the Iranian arrived in the UK in January 2003 and claimed asylum but his application was refused in October that year.
In February 2004 he was convicted of indecent assault and sentenced to 12 months' imprisonment and served with a deportation order.
After completing his sentence, he was in immigration detention for a total of 55 months across two spells - first between March 2005 to December 2007 and then from January 2008 to December 2009.
He was released when the High Court granted him permission to apply for judicial review and the Home Office was ordered to release him on bail.
After he brought proceedings in the UK, his detention from September 2009 was found to have been unlawful and he was awarded £6,150.
In the latest case, J.N. complained to the Strasbourg-based European Court of Human Rights (ECHR).
He argued that the length of his detention was in breach of Article 5 of the European Convention, which covers the right to liberty and security.
In its judgment, the ECHR said there had been a violation in respect of the detention from mid-2008 to September 14 2009.
It found it was "difficult to agree" that there was an adequate basis for the conclusion that the applicant's detention became unlawful only on September 14 2009.
The court said that "in light of the fact that, with the exception of a period of just under one month, the applicant had been in immigration detention since 21 March 2005, and having particular regard to the clear findings of the Administrative Court concerning the authorities' 'woeful lack of energy and impetus' from mid-2008 onwards, the Court considers that it is from this point that it cannot be said that his deportation was being pursued with 'due diligence'."
However, it found the UK's system of immigration detention did not in principle fall short of the requirements under the article.
The court ordered the British Government to pay the man 7,500 euro in damages and 10,000 euro in costs and expenses - equivalent to £13,400.