A Manhattan federal judge on Thursday ordered Michael Cohen released from prison, finding that his June 9 remand into custody was done in retaliation for his forthcoming tell-all book about his time working as President Donald Trump's personal attorney.

U.S. District Judge Alvin K. Hellerstein of the Southern District of New York said in a hearing that in his 21 years on the bench, he had "never seen" a clause requiring that a candidate for home confinement agree not to speak to the media, and he roundly rejected the government's claims that Cohen's jailing was the result of his failing to cooperate with the terms of his release.

"I make the finding," Hellerstein said, "that the purpose of transferring Mr. Cohen from furlough and home confinement to jail is retaliation, and it's retaliation because of his desire to exercise his First Amendment rights."

Under Hellerstein's order, Cohen, who has been under quarantine at FCI Otisville, would be tested for COVID-19 and released from prison by 2 p.m. Friday. Cohen's attorneys agreed that he would still comply with the gag order until they could negotiate a new agreement with the Manhattan U.S. Attorney's office that would not violate their client's rights under the U.S. Constitution.

While Cohen would be allowed to write and edit his book, Hellerstein did, however, note that Cohen's release would come with some restrictions on his interactions with the media.

Attorney's said they would need about a week to work out a new agreement.

Cohen had sued the federal Bureau of Prisons and U.S. Attorney General William Barr on Monday, claiming that officials had sent him back to prison in order to prevent him from publishing his book. According to the lawsuit, the book describes Cohen's "first-hand" experience working as the president's fixer and includes accounts of anti-Semitic and "virulently racist" remarks that Trump had allegedly made about Black leaders, including President Barack Obama and Nelson Mandela

In a statement, Cohen's attorney, Danya Perry, said Hellerstein's order was a "victory for the First Amendment and we appreciate the judge's ruling confirming that the government cannot block Mr. Cohen from publishing a book critical of the president as a condition of his release to home confinement."

"This principle transcends politics and we are gratified that the rule of law prevails," said Perry, who argued at Thursday's hearing.

Government lawyers from the Manhattan U.S. Attorney's Office, which had prosecuted Cohen in 2018 for tax fraud and lying to Congress, denied any link between the book and Cohen's remand, claiming that he had refused to sign off on the reasonable terms of his release.

In court papers, they cited a signed declaration by Cohen's probation officer, who said that Cohen and his attorney, Jeffrey Levine, had been "combative" during the July 9 meeting and challenged "nearly every provision" of an electronic monitoring agreement to allow Cohen to serve out the remainder of his three-year prison sentence from home.

The decision, they said, had been "instigated" by the probation officer, Adam Pakula, and was ultimately approved by a BOP official with "no knowledge" of Cohen's upcoming book.

On Thursday, Hellerstein said there was no reason to attribute Cohen's hesitation to "intransigence." Rather, he said, the meeting appeared to be a standard negotiation by an attorney on behalf of his client.

"People object and then there are negotiations and discussions, and once people realize they can't move any further, they agree," Hellerstein said. "Mr. Cohen and Mr. Levin were never given a change to agree."

"What's an attorney for," the judge asked, "if he's not going to negotiate an agreement for his client?"

A spokesman for the U.S. Attorney's Office declined to comment Thursday.

READ MORE: