PHILADELPHIA — To catch a Philadelphia municipal judge they suspected of corruption, FBI agents invented a defendant — complete with a staged arrest and court appearances.

Court documents from Judge Joseph Waters Jr.’s guilty plea Wednesday to federal mail and wire fraud charges include details of the bogus arrest of a man named David Khoury for illegally carrying an unloaded Glock .40-caliber pistol during a 2012 traffic stop, The Philadelphia Inquirer reported.

According to the documents, an unnamed campaign donor asked Waters to help Khoury, describing him as a cousin of a business associate.

Waters then called a fellow judge who was scheduled to hear the case. According to Waters’ plea document, he identified Khoury as a friend and asked the judge hearing the case to help him.

Prosecutors and defense lawyers who worked briefly on Khoury’s case barely remembered the man, and were not in on the FBI’s secret.

“As I understand it, none of it was real. This whole sting was orchestrated,” Waters’ attorney, Michael Engle, said.

The police report on the Khoury arrest said that the arresting officer, John Snyder, pulled Khoury over in May 2012 for driving erratically on a busy stretch of Torresdale Avenue in Philadelphia.

“When I approached the window, I asked him for his information,” Snyder testified later at a hearing in the case. “I noticed a black handgun on the floor mat area. I asked if he had a license to carry. He said ‘no.'”

The fake 40-year-old defendant was charged with carrying a firearm without a license, a felony. He told officers that he did not know his address and had no phone. He told probation officers he was from Louisville, Kentucky, and gave a Social Security number that appeared to have been issued in Texas in 1988. His black SUV had Virginia plates.

It remains unclear whether Snyder knew the Khoury case was a sting. He declined comment on it last week to the Inquirer.

Ultimately, the judge hearing the case reduced the charge to a misdemeanor. The charges were ultimately dropped when the fake defendant failed to appear for trial and court staff had no address on file.

All that remains of Khoury’s case is a manila court file on an office shelf in the Philadelphia courts building. On it is a single green sticky note that reads, “Withdrawn – FBI.”