A corrupt Philadelphia judge met his downfall after FBI agents set up a fake trial, including a fake defendant, to catch him in the act.

Municipal Judge Joseph Waters was caught asking a fellow judge to fix a case in favor of a man who was arrested for carrying an unlicensed pistol in 2012, the Philadelphia Inquirer reported.

The man, David P. Khoury, was actually an undercover agent, whose arrest and trial was staged, court records obtained by the newspaper revealed. Waters pleaded guilty last Wednesday to federal mail fraud and wire fraud.

"As I understand it, none of it was real," the judge's attorney, Michael J. Engle, told the newspaper. "This whole sting was orchestrated."

The mock trial was set in motion when the undercover agent identified as Khoury was arrested in May 2012 during a traffic stop in Holmesburg. The cop who stopped Khoury saw a handgun inside his vehicle and arrested him for the felony charge. None of the lawyers involved in his arrest knew about the sting but it's unclear clear if the arresting officer had prior knowledge. 

Shortly after the fake arrest, an unnamed campaign donor contacted Waters and asked if he could help manipulate the system for Khoury, whom the donor said was the relative of a business associate.

Waters heartily accepted the request from the donor, who in 2010 donated $1,000 in cash to Waters' campaign, the newspaper reported.

"You run into a problem with any of your people, you get a hold of me," Waters told the donor according to court records. "Anything I can do to help you or anybody that you're interested in, all you do is pick up the phone and call me."

Waters then called Municipal Court Judge Dawn Segal, who was presiding over a hearing for Khoury's case. Waters told her Khoury was a "friend" and entreated her to "help him," according to Waters' plea record obtained by the Philadelphia Inquirer.

In July 2012, Segal reduced Khoury's felony charge to a misdemeanor, a ruling which federal officials said had no "proper legal basis." She has since been pulled from the bench and is under investigation by the Pennsylvania Judicial Conduct Board. It is not clear if she faces criminal charges.

Stuart L. Haimowitz, a layer for Segal, said the judge thought she was making the right choice and would have given the same ruling whether or not the case was real.

Staged prosecutions are rare in the legal system. However, when they are done, prosecutors do a lot of consulting with federal officials in Washington, D.C., and usually seek approvals from the FBI and the Department of Justice, a spokeswoman from the U.S. Attorney's Office in Philadelphia told the newspaper.