The Justice Department will move forward with its defense of former President Donald Trump in a defamation suit brought by a journalist over allegations that the former president raped her in the 1990s.

In a filing in New York federal court on Monday, the Justice Department signaled that it wouldn’t change position in the case, despite President Biden’s appointees taking control of the department in January.

The dispute was sparked after E. Jean Carroll, a longtime advice columnist for Elle magazine, made the allegation in an article published in New York Magazine in 2019. She wrote that in the mid-1990s Mr. Trump pushed her against a dressing-room wall at Bergdorf Goodman in New York and assaulted her.

After her allegations appeared in print, Mr. Trump replied: “Number one, she’s not my type. Number two, it never happened.” In response, Ms. Carroll sued the then-president in November 2019, saying he lied earlier that year when he denied raping her.

The Justice Department under Mr. Trump intervened last September, asking that the U.S. government be named as the plaintiff rather than Mr. Trump personally. Under existing law, the federal government can’t be sued for defamation, and the Justice Department argued that Mr. Trump was acting within the scope of his duties as president when he denied the allegation.

A New York district court judge disagreed and denied the attempt to substitute the U.S. government for Mr. Trump, which would have brought the case to a halt. The case then went to the Second Circuit Court of Appeals, which must now consider the matter.

The Justice Department maintained that position in a new brief filed Monday, saying that the suit against Mr. Trump should be dismissed because as a federal employee at the time of the allegations in question, he is immune from such suits.

“Then-President Trump’s response to Ms. Carroll’s serious allegations of sexual assault included statements that questioned her credibility in terms that were crude and disrespectful. But this case does not concern whether Mr. Trump’s response was appropriate,” the department told the New York-based federal appeals court that will consider the matter.

“Speaking to the public and the press on matters of public concern is undoubtedly part of an elected official’s job. Courts have thus consistently and repeatedly held that allegedly defamatory statements made in that context are within the scope of elected officials’ employment—including when the statements were prompted by press inquiries about the official’s private life,” the department maintained.

“It is truly shocking that the current Department of Justice would allow Donald Trump to get away with lying about it, thereby depriving our client of her day in court. The DOJ’s position is not only legally wrong, it is morally wrong since it would give federal officials free license to cover up private sexual misconduct by publicly brutalizing any woman who has the courage to come forward,” Roberta Kaplan, a lawyer for Ms. Carroll said.

Mr. Trump’s legal team and a Justice Department spokesperson didn’t immediately respond to a request for comment.

It is uncommon for the Justice Department to abruptly switch litigation positions between administrations. Department leaders often prefer consistency and institutional considerations over political ones. Establishing a precedent that Mr. Trump can be sued for defamation over a statement he made while in office could bog future presidents down in litigation, for example.

However, Mr. Biden had pointedly criticized the Justice Department’s handling of the Carroll matter during the 2020 presidential election, saying that Mr. Trump had abused the department by forcing it to defend him personally in lawsuits like the one brought by Ms. Carroll as well as extended litigation over Mr. Trump’s tax returns that involved the department.

Mr. Biden has also said that he doesn’t want to be involved in Justice Department decisions.

Write to Byron Tau at byron.tau@wsj.com