A Manhattan federal judge has ordered that Donald Trump’s former personal attorney, Michael Cohen, be released by Friday, after he had been sent back to a New York prison for resisting the terms of home confinement. Judge Alvin K. Hellerstein, in a 36-minute tele-hearing Thursday, found that returning Cohen from home confinement to jail was “retaliatory,” that it punished Cohen “because of his desire to exercise his first amendment rights to publish a book and to discuss anything about the book or anything else he wants on social media and with others.” Cohen is to be released no later than 2 p.m. Friday, and must take a COVID-19 test before his release. “Mr. Cohen will be confined to his home except for conditions in his agreement,” the judge said. The decision comes after Cohen had sued Attorney General Bill Barr and the director of the Bureau of Prisons, arguing that being sent back to prison was a violation of his constitutional rights. Cohen had publicly announced that he was in the process of writing a book about his former employer, President Trump, and said that being thrown back in prison was a form of retaliation. Cohen was sent home in May because of the coronavirus pandemic but was detained again on July 9 after questioning an agreement that would prevent him from publishing his book, speaking to news organizations and posting on social media. Prosecutors argued in a court filing Wednesday that Cohen had been “combative” during the July 9 meeting when Cohen was supposed to sign off on the terms of his Federal Location Monitoring Program agreement. Cohen took issue with nearly every provision of an agreement that would have let him finish his sentence at home, prosecutors said. Among the provisions were the media ban, electronic monitoring and approval for employment. They also maintained that Cohen is “free to work on his book while incarcerated.” His lawsuit stated that he was being held in solitary confinement. But the government’s court filing said he was in a 14-day quarantine that is standard for all new inmates and is meant to protect other inmates from potential infection. The filing said two of 63 inmates are considered “active COVID-19 cases.” The government’s court filing noted that Cohen had been spotted dining out at Manhattan restaurants, and said while that was not a factor in his return to prison, it did undercut Cohen’s argument that he was concerned about his health. He will now serve the remainder of his three-year sentence from home. In 2018, Cohen pleaded guilty to financial and campaign finance crimes and lying to Congress about his involvement in an effort to build a “Trump Tower” in Moscow during the 2016 campaign. Cassandra Gauthier contributed to this report.