Updated

A federal court ruled that the Justice Department cannot take President Trump's place as the defendant in a lawsuit filed by writer E. Jean Carroll, who sued for defamation over Trump's response to her allegations that he raped her in the 1990s.

Trump had claimed that he never met Carroll, and accused her of fabricating the allegations to sell her book or to "carry out a political agenda." The Justice Department cited statutes that call for the United States to replace a government employee in a lawsuit arising over actions carried out in the course of their duties, but the court ruled that those statutes did not apply.

NYC JOINING PORTLAND, SEATTLE TO SUE TRUMP ADMIN OVER DEFUNDING FOR 'ANARCHIST JURISDICTIONS'

"President Trump’s comment concerned media reports about an alleged sexual assault that took place more than 20 years before he took office. Neither the media reports nor the underlying allegations have any relationship to his official duties," U.S. District Court Judge Lewis A. Kaplan of the Southern District of New York wrote in a Tuesday opinion.

The DOJ had argued that by denying Carroll’s allegations, Trump was making it easier for himself to govern due to the seriousness of the accusation. Kaplan said that the DOJ had waived that argument by waiting too long to make it, but even so, it was not convincing.

BARR DEFENDS DOJ INTERVENTION IN E. JEAN CARROLL LAWSUIT AGAINST TRUMP: 'THE LAW IS CLEAR'

 “While the government’s position is not entirely without merit, it goes much too far. Accepting it would mean that a president is free to defame anyone who criticizes his conduct or impugns his character – without adverse consequences to that president and no matter what injury he inflicts on the person defamed.”

Before even getting into the nature and context of the president's statements, however, Kaplan ruled that the president does not qualify as an "employee" of a "federal agency" for the purposes of the statutes that would allow the government to take his place – the Federal Tort Claims Act and the Westfall Act.

The Justice Department declined to comment on the decision.

CLICK HERE TO GET THE FOX NEWS APP

Carroll celebrated the court's decision, looking forward to continuing the litigation.

"When I spoke out about what Donald Trump did to me in a department store dressing room, I was speaking out against an individual. When Donald Trump called me a liar and denied that he had ever met me, he was not speaking on behalf of the United States," Carroll said in a statement. "I am happy that Judge Kaplan recognized these basic truths. As the judge recognized today, the question whether President Trump raped me 20 years ago in a department store is at 'the heart' of this lawsuit. We can finally return to answering that question, and getting the truth out."

Fox News' Marta Dhanis and David Spunt contributed to this report.