A judge has said sorry after he awarded a sex attacker £110,000 because he was kept in prison for too long.
Aliou Bah, 28, a refugee from Guinea, was twice jailed for sex assaults, including one on a 16-year-old girl.
However, he was kept in prison for an extra 21 months after serving his sentences while the Home Office tried to get him deported back to West Africa.
Judge Nicholas Madge blamed a series of Home Office blunders that led to his extended detention.
He said that it is the victims of sexual abuse who should be paid large sums of compensation, not their attackers.
However, he said that it was his job to uphold the law as he awarded the cash to Bah.
He ruled that because of his refugee status he should have been released.
The Guinea Embassy had refused to issue him with travel documents, so there was never any prospect of deporting him anyway, he added.
Bah arrived in the UK in 2007 and was jailed for 18 months for sexually assaulting the 16-year-old girl in 2011.
He was jailed again for two years after a sexual assault in 2014.
The Home Secretary signed a deportation order against him in December 2011, without anyone realising that he was entitled to be treated as a refugee.
He he was held in prison for 14 months between January 2012 and March 2013, pending a deportation that could never have happened.
He was held again, this time for seven months, between October 2014 and June 2015, again unlawfully.
Given his refugee status and the attitude of the Guinea Embassy, there was no prospect of him being thrown out of the country, said the judge.
The Guinea authorities have consistently refused to issue travel papers to anyone who does not want to return to the country voluntarily.
Bah had not volunteered to go home and the judge said that noone had been successfully deported to the West African state since 2006.
Both periods of immigration detention were therefore necessarily unlawful, the judge ruled.
More: Crime news
Making the award, the judge said there were few more important principles in a civilised society than that noone must be locked up without lawful authority.
Bah was entitled to justice, like anyone else, and it was the role of independent judges to hold the government to account.
He had served his punishments for his crimes and was only due compensation because of the Home Office’s failure to properly apply its own policy.
Judge Madge concluded that, had Home Office officials behaved in a competent manner, the need to award Bah damages would not have arisen.