President Donald Trump’s former lawyer and fixer, Michael Cohen, was ordered freed from prison after a U.S. judge ruled he was locked up in retaliation over a planned book criticizing Trump.

Cohen, who pleaded guilty in August 2018 to crimes tied to his work for Trump, sued the government on Monday alleging his deal to serve the rest of his three-year term at home due to the coronavirus pandemic was withdrawn because he refused to sign away his right to communicate with the media, including through books.

U.S. District Judge Alvin K. Hellerstein in Manhattan on Thursday ordered the U.S. to release Cohen by Friday at 2 p.m. after he receives a test for COVID-19.

Hellerstein rejected the government’s claim that Cohen had been returned to prison because he refused to sign the deal. The judge said Cohen and his lawyer did nothing wrong by questioning the provisions and seeking to negotiate more favourable terms.

“In 21 years of being a judge and sentencing people and looking at terms of supervised release I’ve never seen such a clause,” Hellerstein said of a provision. The clause had the clear effect of telling Cohen to “tow the line or we’ll send you to jail and call you intransigent.”

The suit, filed with help from the American Civil Liberties Union, accused Attorney General William Barr and Bureau of Prisons Director Michael Carvajal of using a false justification to lock him up again and violating his First Amendment right to free speech.

Cohen has said he is planning to release a book in September.