A U.S. District judge on Thursday ruled that federal prosecutors illegally signed a plea agreement with convicted sex offender Jeffrey Epstein and hid it from his more than two dozen underage victims.

“Epstein used paid employees to find and bring minor girls to him.,’’ wrote U.S. District Judge Kenneth A. Marra of Palm Beach County. “Epstein worked in concert with others to obtain minors not only for his own sexual gratification, but also for the sexual gratification of others.’’

Epstein, now 66, reached a nonprosecution deal in 2008 with then-Miami U.S. Attorney Alexander Acosta’s office to secretly end a federal sex abuse investigation involving at least 40 teenage girls that could have landed him behind bars for life. He instead pleaded guilty to state charges, spent 13 months in jail, paid settlements to victims and is a registered sex offender.

Acosta, now President Donald Trump’s labor secretary, has defended the deal as appropriate but has not commented since the recent round of stories. He was asked about the case during his Senate confirmation hearings for the Cabinet post.

“At the end of the day, based on the evidence, professionals within a prosecutor’s office decided that a plea that guarantees someone goes to jail, that guarantees he register generally and guarantees other outcomes, is a good thing,” he said.

Earlier February, the Justice Department opened an investigation into federal prosecutors’ handling of the plea deal.

The department’s Office of Professional Responsibility wrote in a letter to Sen. Ben Sasse that it would examine whether professional misconduct occurred in the highly publicized case of Epstein. The letter cited a series of recent articles by the Miami Herald that focused new attention on how the deal came about.

Sasse, a member of the Senate Judiciary Committee who has twice asked the Justice Department to investigate the case, welcomed the news.

“Jeffrey Epstein is a child rapist and there’s not a single mom or dad in America who shouldn’t be horrified by the fact that he received a pathetically soft sentence,” Sasse said in an email. “The victims of Epstein’s child sex trafficking ring deserve this investigation — and so do the American people and members of law enforcement who work to put these kinds of monsters behind bars.”

The Associated Press contributed to this report.