Updated

Former Trump attorney Michael Cohen was released from prison Friday and is expected to return to home confinement in his New York City apartment after a federal judge ruled that his return to imprisonment was “retaliatory” and related to his forthcoming tell-all book.

The Associated Press reported that Cohen was released from Federal Correctional institute Otisville in upstate New York Friday.

JUDGE ORDERS MICHAEL COHEN RELEASED TO HOME CONFINEMENT, SAYS IMPRISONMENT WAS 'RETALIATORY' OVER FORTHCOMING BOOK

Cohen sued Attorney General Bill Barr for allegedly violating Cohen’s First Amendment rights when he was remanded earlier this month, but U.S. District Judge for the Southern District of New York Alvin Hellerstein on Thursday said the move to send Cohen back to prison was "retaliatory" and believed it was related to his book.

Hellerstein said he determined "the purpose of the transferring" was "because of his desire to exercise his First Amendment rights to publish a book and discuss anything about the book.”

"That’s my essential finding and the injunction is against continuing retaliation against Mr. Cohen by keeping him in jail when he should be confined as he was before the retaliation at home,” the judge said.

The Bureau of Prisons on Thursday denied the judge’s claims in a statement, saying, “Any assertion that the decision to remand Michael Cohen to prison was a retaliatory action is patently false.”

“While it is not uncommon for BOP to place certain restrictions on inmates’ contact with the media, Mr. Cohen’s refusal to agree to those conditions here played no role whatsoever in the decision to remand him to secure custody nor did his intent to publish a book,” the statement said.

COHEN SUES BARR, CLAIMS HE WAS SENT TO PRISON TO PREVENT TRUMP TELL-ALL

Cohen was released from New York's Otisville Correctional Facility in May amid concerns over coronavirus and was ordered to serve the remainder of his sentence in home confinement.

But earlier this month, Cohen was taken back into custody after having violated the terms, according to the federal Bureau of Prisons.

Michael Cohen dining out with three other people at the Le Bilboquet restaurant located at 20 E60th Street in New York, NY on July 2, 2020. (Photo/Christopher Sadowski)

Michael Cohen dining out with three other people at the Le Bilboquet restaurant located at 20 E60th Street in New York, NY on July 2, 2020. (Photo/Christopher Sadowski) (Mandatory Courtesy: Christopher Sadowski)

Reports said Cohen was seen at a restaurant in Manhattan, which raised concerns that he was in violation of his home confinement terms. Levine did not say whether his visit to the New York City restaurant was connected to his latest arrest.

Michael Cohen dining out with three other people at the Le Bilboquet restaurant located at 20 E60th Street in New York, NY on July 2, 2020. (Photo/Christopher Sadowski) Tags: postinhouse nypostinhouse

Michael Cohen dining out with three other people at the Le Bilboquet restaurant located at 20 E60th Street in New York, NY on July 2, 2020. (Photo/Christopher Sadowski) Tags: postinhouse nypostinhouse (Mandatory Courtesy: Christopher Sadowski)

Cohen was convicted of several charges including campaign finance violations in connection with hush payments made to women who claimed to have had affairs with Trump in the past. He started serving his sentence in May 2019 and was scheduled to be released in November 2021.

Fox News’ Marta Dhanis and The Associated Press contributed to this report.