MIAMI — Prosecutors led by Alexander R. Acosta, who is now the secretary of labor, violated federal law when they failed to tell victims about an agreement not to prosecute Jeffrey E. Epstein, a wealthy New York financier accused of molesting dozens of underage girls, a federal judge ruled on Thursday.

The agreement not to pursue federal sex trafficking charges, negotiated in secret while prosecutors told victims that a case against Mr. Epstein was still possible, violated the federal Crime Victims’ Rights Act, ruled Judge Kenneth A. Marra of Federal District Court in West Palm Beach, Fla. He gave the government and the two victims who sued 15 days to discuss what remedy should apply in the case.

Federal prosecutors had initially drafted a 53-page indictment against Mr. Epstein, but under the deal negotiated in 2008, he pleaded guilty to lesser state charges of soliciting a minor for prostitution and served 13 months at the Palm Beach County Stockade. While there, Mr. Epstein was allowed to leave custody and work out of his office six days a week.

The court’s ruling on Thursday could nullify the non-prosecution agreement and subject Mr. Epstein and any co-conspirators in the case to new federal charges, said Jack Scarola, a lawyer for the two victims who challenged the agreement.