A federal judge on Monday dismissed a lawsuit brought by former Trump attorney Michael Cohen alleging former President Trump and the U.S. government retaliated against him for writing a tell-all memoir by placing him in federal prison.

Cohen had been sentenced to prison in 2019 for crimes including tax evasion, campaign finance violations and lying to Congress. He was released to home confinement after a year amid the coronavirus pandemic in 2020.

Michael Cohen

FILE PHOTO: Michael Cohen, U.S. President Donald Trump's former lawyer, leaves his apartment to report to prison in Manhattan, New York, U.S., May 6, 2019. (REUTERS/Jeenah Moon TPX IMAGES OF THE DAY/File Photo)

Cohen was ordered back to prison weeks later after the Federal Bureau of Prisons said Cohen violated "the conditions of his home confinement." Reports, at the time, had shown Cohen at a restaurant in Manhattan, which raised concerns he was in violation of the terms of confinement, but it is unclear if that outing was connected to his return to prison.

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.  (Mandatory Courtesy: Christopher Sadowski)

Cohen, at the time, claimed he had only sought clarification on a condition which blocked him from speaking with the media and from publishing his book.

Cohen and his legal team filed a lawsuit against Trump and then-Attorney General Bill Barr in July 2020 after returning to prison for allegedly violating his First Amendment rights and retaliating against him. 

"He is being held in retaliation for his protected speech, including drafting a book manuscript that is critical of the President—and recently making public his intention to publish that book soon, shortly before the upcoming election," the petition read.

MICHAEL COHEN, FORMER TRUMP ATTORNEY, SAYS HE HAS COMPLETED HIS PRISON SENTENCE

U.S. District Judge for the Southern District of New York Lewis Liman, who threw out Cohen’s case on Monday, explained that the first paragraph of conditions for Cohen’s home confinement included a "broad provision prohibiting Cohen from engaging with the media in any form, including books, and from posting on social media." 

But Liman, in his order Monday, said Cohen’s allegations are "ambiguous" and "not clear."

MICHAEL COHEN CAUGHT AT NEW YORK CITY RESTAURANT — AND IT COULD LAND HIM BACK IN PRISON

Cohen had claimed that when he returned to prison, he suffered shortness of breath, severe headaches and anxiety in a small cell at the federal prison in Otisville, New York.

Donald Trump speaks at CPAC

Former U.S. President Donald Trump speaks at the Conservative Political Action Conference (CPAC) at the Hilton Anatole on August 06, 2022, in Dallas, Texas. (Brandon Bell/Getty Images)

But Liman said it is unclear whether the alleged "negligence" resulted from policies at the prison, which, Liman said "allowed for the unsafe conditions in Cohen’s cell to occur perhaps due to concerts about costs or resource allocation," or "from the carelessness of an individual guard in failing to check that the cell was well-ventilated, air conditioned, and a safe temperature." 

MICHAEL COHEN, FORMER TRUMP ATTORNEY, TAKEN BACK INTO CUSTODY

The judge had asked Cohen’s legal team to clarify which theory he was alleging, to which they replied that he was "only alleging that the ‘policies and procedures in place during COVID at Otisville were egregiously bad in that they, aside from deliberately indifferent, were just negligent in the maintenance and upkeep." 

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

Liman, on Monday, though, wrote that Cohen "admitted that he was not asserting a negligent guard theory of liability," which he said, "unfortunately for Cohen," was "fatal to his ability to assert" his claim. 

WASHINGTON, DC - DECEMBER 21: US Attorney General Bill Barr holds a news conference to provide an update on the investigation of the terrorist bombing of Pan Am flight 103 on the 32nd anniversary of the attack, at the Department of Justice December 21, 2020, in Washington, DC. Barr announced criminal charges against one of the alleged Libyan bombmakers. The bombing occurred on December 21, 1988, killing all 259 people on board and eleven on the ground in Lockerbie, Scotland.  ((Photo by Michael Reynolds-Pool/Getty Images))

"[T]hus, Cohen’s claim of negligent failure to protect must be dismissed accordingly," Liman stated. 

Trump lawyer Alina Habba characterized the ruling as a "victory."

Michael Cohen wears mask

Michael Cohen arrives at his Manhattan apartment, Thursday, May 21, 2020, in New York. President Donald Trump's longtime personal lawyer and fixer was released federal prison Thursday and is expected to serve the remainder of his sentence at home. Cohen has been serving a federal prison sentence at FCI Otisville in New York after pleading guilty to numerous charges, including campaign finance fraud and lying to Congress. (AP Photo/John Minchillo)

"Today we scored another victory against Michael Cohen," Habba told Fox News. "The Court saw through Mr. Cohen’s frivolous lawsuit, which was legally deficient and, more importantly, based upon inflammatory allegations that are simply not true."

Habba added: "President Donald J. Trump will continue to fight for the truth and against innumerable falsehoods being perpetrated by his enemies."

Cohen, in a statement to Fox News on Tuesday, said he disagreed with Liman's decision. 

"At every turn I have been silenced or derailed in my efforts to expose the unethical and unconstitutional tactics used against me by the previous administration," Cohen said. "Despite all this, I will not be deterred in continuing my journey of speaking truth to power." 

Fox News' Marta Dhanis contributed to this report.