The ruling is the latest twist in a long-running legal saga involving Cohen, who once said he would "take a bullet" for Trump.
President Donald Trump's former personal lawyer Michael Cohen left prison to finish his criminal sentence at home, a day after a judge found he was sent back behind bars two weeks ago as retaliation for plans to publish a book about Trump.
Cohen was picked up at a prison in Otisville, New York, about 110 km northwest of New York City, about 05.00 pm GMT by his son and his brother, attorney Jeffrey K. Levine, said. Cohen was expected to be fitted for an ankle monitor and then be driven to his Manhattan apartment.
He had been returned to prison on July 9 after being furloughed in May because of concerns about the spread of the novel coronavirus.
US District Judge Alvin Hellerstein on Thursday ordered Cohen released by 06.00 pm GMT on Friday.
“He looked exhausted, as one might think, when you come out of quarantine/solitary confinement," said Levine, who saw Cohen over FaceTime from the car. "He hasn't slept in two weeks."
On July 9, Cohen and Levine met with probation officials to convert his furlough to a home confinement for the final two years of his three-year sentence. After Cohen questioned a provision that barred him from publishing the book, engaging with news organisations and posting on social media, officials shackled him and returned him to prison.
Hellerstein said in Thursday's court hearing that he had never seen such a gag provision in his 21 years on the bench.
"It's retaliatory because of his desire to exercise his First Amendment rights to publish a book," Hellerstein said.
Cohen may file a lawsuit seeking compensation for his unlawful imprisonment and violation of his First Amendment rights, Levine said.
"The lawsuit will get deeper into how this happened and who ultimately was responsible," Levine said.
The Federal Bureau of Prisons, in a statement after the judge's ruling, said that the book played no role in the decision to return Cohen to prison. The bureau did not immediately respond to a request for comment on Cohen's departure from prison.
Reasons for conviction
Cohen, who once said he would “take a bullet” for Trump, was sentenced in 2018 for crimes that included campaign finance violations for directing hush payments to pornographic film star Stormy Daniels and former Playboy model Karen McDougal, who said they had affairs with Trump before he became president.
Trump has denied having the encounters and has called Cohen a "rat."
In court papers, Cohen said the book will contain his experiences and observations from the decade he worked for Trump, including both before and after he became president. Cohen said it would provide "unflattering details" of Trump's behaviour.
While he turned on Cohen, Trump has voiced support for people who remained loyal to him. A day after Cohen was sent back to prison, Trump commuted longtime friend and adviser Roger Stone's prison sentence for lying under oath to lawmakers investigating Russian interference in the 2016 US election.