A federal judge Tuesday rejected the Justice Department’s bid to make the U.S. government the defendant in a defamation lawsuit brought by a woman who says President Trump raped her decades ago, paving the way for the case to again proceed.

In a 59-page ruling, U.S. District Judge Lewis A. Kaplan wrote that Trump did not qualify as a government “employee” under federal law, nor was he acting “within the scope of his employment” when he denied during interviews in 2019 that he had raped journalist E. Jean Carroll in a Manhattan department store during the 1990s.

Carroll sued Trump over that denial in New York in November, and last month the Justice Department moved the case to federal court and asked a judge to substitute the U.S. government as the defendant. The department argued Trump was “acting within the scope of his office as President of the United States” when he disputed Carroll’s allegations.

The maneuver was a bid to short-circuit the case. If the judge had done what the Justice Department asked, government lawyers could then have invoked the notion of “sovereign immunity” — which prohibits lawsuits against the government — to end the case.

“The President of the United States is not an ‘employee of the Government’ within the meaning of the relevant statutes,” the judge wrote. “Even if he were such an ‘employee,’ President Trump’s allegedly defamatory statements concerning Ms. Carroll would not have been within the scope of his employment.”

The case, though, will remain in federal court, and the Justice Department’s maneuver by itself stalled proceedings that might have been politically damaging for Trump ahead of next week’s election.

A month before the Justice Department intervened, a New York judge had rejected Trump’s bid to delay the case. That put Carroll’s team on course to seek a DNA sample for comparison to biological material found on the dress Carroll says she wore the day she was sexually assaulted, as well as an under-oath interview from the president, through a process known as discovery.

It is possible there will be more arguments over those and other discovery matters, with the president fighting the case in his personal capacity. The Justice Department could also appeal the ruling.

A Justice Department spokeswoman did not immediately respond to requests for comment. Roberta Kaplan, an attorney for Carroll, said she was “very pleased that the federal court interpreted the plain text of Federal Tort Claims Act as not covering President Trump’s false statements about our client.”

“The simple truth is that President Trump defamed our client because she was brave enough to reveal that he had sexually assaulted her, and that brutal, personal attack cannot be attributed to the Office of the President,” she said in a statement, adding that Carroll’s team looked forward to proceeding with the case in federal court.

Carroll said in a statement: “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. I am happy that Judge Kaplan recognized these basic truths.”

While the Justice Department commonly intervenes in cases where federal employees are sued, the move in the suit against Trump generated significant controversy, as critics of the administration felt the president was deploying federal resources to protect himself in a personal matter. Attorney General William P. Barr, though, defended the move, asserting that legal precedent was on the government’s side and that any uproar was due to the country’s “bizarre political environment.”

He said the White House had sent a memorandum to the Justice Department seeking the intervention, and civil litigation experts at the department agreed, in keeping with the normal procedure for such legal questions.

Tuesday’s ruling hinged on technical questions having to do with two laws — the Federal Tort Claims Act, or FTCA, and the Westfall Act — which govern how and when federal employees can be sued. The judge wrote that he had to assess first whether Trump, as president, counted as a federal “employee” under the law, and if he did, he had to weigh whether the statements about Carroll came within the scope of that employment.

“The answer to both questions is ‘no,’ ” the judge wrote. “While the president possesses all of the executive power of the United States, he is not an ‘employee’ within the meaning of the FTCA. The FTCA’s definition of that term does not include presidents. And even if the president were an employee under that statute, his statements concerning Ms. Carroll were not within the scope of his employment under the law of the relevant jurisdiction.”

The Justice Department had argued in a written filing this month that past court cases had concluded that any public statements that reflect on the character and trustworthiness of a public official fall under the law. Because Carroll’s accusation called into question “the President’s fitness for office,” the Justice Department lawyers argued, “a response was necessary for the President to effectively govern.”

But the judge noted in his ruling that he explicitly disagrees with the prior court case frequently cited by the Justice Department, which gives wide latitude for the government to claim members of Congress are exempt from lawsuits for all manner of public statements about personal matters.

Kaplan also analyzed at length “master-servant” case law, finding that Trump’s statements were not done because he had some obligation to a higher-ranking employer.

“The president is no one’s servant,” the judge wrote, therefore his statements were not driven in any way “by a purpose to further the master’s business,” as described in previous D.C.-based cases.

“At its core, the government’s argument is that speaking to reporters is part of the president’s job. Thus, it argues, whenever the president speaks to reporters — no matter the topic — he is acting within the scope of his employment,” Kaplan wrote, adding, “the Court is not persuaded.”

The judge went further, saying that the subject of the Carroll lawsuit is far beyond any topic that could reasonably be considered part of the work of elected officials.

“His comments concerned an alleged sexual assault that took place several decades before he took office, and the allegations have no relationship to the official business of the United States,” the judge wrote. “To conclude otherwise would require the Court to adopt a view that virtually everything the president does is within the public interest by virtue of his office.”

Justice Department lawyers and Carroll’s team were supposed to square off with in-person arguments in court last week, but the hearing was canceled after one of the Justice Department lawyers, a Virginia resident, was denied entry to the courthouse in Manhattan due to the local quarantine rules. The Justice Department declined the judge’s offer to conduct the hearing via phone conference.

Carroll, who traveled to the courthouse from Upstate New York for the hearing, said at the time she was disappointed and “stunned” by the turn of events.

Jacobs reported from New York.