A federal judge on Tuesday dismissed all charges against more than a dozen people accused of bribing a foreign official in a high-profile Justice Department sting that has suffered setbacks in court.

In a sharply worded ruling from the bench, U.S. District Judge Richard Leon of the District’s federal court applauded federal prosecutors for seeking dismissal of the charges but also criticized them for engaging in what the judge called a “long and sad chapter in the annals of white collar criminal enforcement.”

“I, for one, hope this very long, and I’m sure expensive, ordeal will be a true learning experience for both the [Justice] Department and the FBI,” the judge said, reiterating concerns that he had expressed during two trials about “how this case was investigated and conducted.” The judge specifically criticized how prosecutors handled evidence, managed their key informant and pushed an “aggressive” interpretation of conspiracy charges.

Tuesday’s courtroom denouement was a far cry from January 2010, when the Justice Department announced with flourish that it had arrested 22 people on charges of violating the Foreign Corrupt Practices Act (FCPA), a U.S. law that bans payments to foreign officials in exchange for business.

The defendants were accused of paying a $1.5 million bribe to the defense minister of the small African nation of Gabon to win a $12 million contract to outfit its presidential guard with arms and other supplies. What the participants didn’t know was that there was no deal — it was a ruse by federal agents investigating violations of the FCPA.

At first blush, the case seemed solid. FBI agents from the bureau’s Washington field office videotaped and recorded many of the meetings and phone conversations in which an informant and undercover agents invited executives to participate in the deal and then explained its terms. Three men quickly pleaded guilty to charges stemming from the sting.

Then, during two lengthy trials, the prosecution unraveled. It turned out that the agents and their key informant — a former executive at a body armor company — never used the word “bribe” or “kickback” on tape; instead, they called the payment a “commission,” a sufficiently vague term that was attacked by defense attorneys.

The agents and their cooperator also were chastised by defense attorneys for exchanging racy text messages. The agents and informant joked about sex, cigars and who might play them in a movie based on the sting, among other things.

Richard Bistrong, the informant, also had a checkered past. He had pleaded guilty to violating the FCPA and admitted to accepting $1.3 million in kickbacks from suppliers during his business days, using prostitutes and having an expensive cocaine habit.

The first trial, of four defendants, ended in a hung jury. In the second trial, of six defendants, which ended last month, the judge acquitted one man before the case reached the jury; two others were found not guilty by jurors; and jurors failed to reach a verdict against three others. The jury foreman later wrote a lengthy blog post criticizing the case and said in an interview that the government’s witnesses had “little credibility,” an assessment echoed by a juror in the first trial.

Tuesday’s hearing came just hours after prosecutors filed a motion asking Leon to drop the charges, citing their lack of courtroom success, what they considered unfavorable judicial rulings and the “substantial government resources” required for more trials. Prosecutors declined to comment after the hearing.

Of the original 22 defendants, three pleaded guilty and three were acquitted. Leon’s ruling Tuesday applies to nine defendants awaiting trial and the seven who were granted mistrials. Those who pleaded guilty may be allowed to petition the court to void their pleas.

Charles Leeper, an attorney for Jeana Mushriqui, whose case ended in a mistrial, said his client was “grateful that the decision-makers at the Department of Justice recognized it was time to bring this case to an end.”

Mike Madigan, an attorney for John Godsey, an Atlanta lawyer who was acquitted by jurors, said the case “was a disaster in many different respects and had no chance of ever convincing 12 members of a jury to convict anyone.”