The FBI was listening in as attorney Benjamin Brafman chatted with a cop-bribing Mayor de Blasio donor — later telling a judge it involved potential NYPD corruption, and citing the late mob boss John Gotti as a precedent.

Brafman — whose clients have included rapper Jay-Z, mobster Vincent “The Chin” Gigante, and most recently, Harvey Weinstein — was recorded as he chatted with Jona Rechnitz, whose cell phone was wiretapped as part of a probe involving ex-NYPD Chief of Department Philip Banks.

The Jan. 15, 2015 wiretap was disclosed in an FBI affidavit filed in Manhattan federal court.

At the time, Brafman was representing Banks in an IRS investigation into more than $500,000 in undeclared income, including about $300,000 worth of deposits into bank accounts controlled by Banks and his wife.

Banks was also suspected by the FBI of having invested $250,000 through Rechnitz with Harlem restaurant owner Hamlet Peralta, who had ties to several high-ranking cops and later pleaded guilty to running a $12 million Ponzi scheme.

Rechnitz pleaded guilty to paying off cops and other officials in exchange for favors, and is set to testify as the star witness at next month’s corruption trial of ex- NYPD Deputy Inspector James Grant and fellow de Blasio donor Jeremy Reichberg.

During their conversation, Rechnitz told Brafman he was “calling you really just to calm me down” following a conversation that FBI agents saw Rechnitz have with Banks outside the Prime KO kosher steakhouse on the Upper West Side the night before, according to the affidavit by Special Agent Joseph Downs.

Rechnitz said Banks told him that “they’re doing this because they’re looking into someone else…maybe Hamlet cause of the plane,” an apparent reference to a December 2013 trip to the Dominican Republic by Rechnitz, Banks and Peralta, Downs wrote.

“Based on what I know, it has nothing to do with you and based on what I know it has to do with him (Banks) and it’s a personal tax issue that has nothing to do with business,” Brafman told Rechnitz, the filing says.

The feds are generally precluded from secretly listening in on lawyers and their clients, but Downs said the agent monitoring the conversation didn’t stop, adding: “The decision was a reasonable one.”

Downs noted that Brafman and Rechnitz had “no known attorney-client relationship,” and even if they did, “the conversation is still not privileged because the crime-fraud exception applies.”

“Specifically, to the extent the conversation relates to ‘contemplated or ongoing criminal or fraudulent conduct — such as the repayment of the $250,000 investment Banks made with Rechnitz to avoid detection — ‘[t]he crime-fraud exception’ effectively ‘strips the privilege’ from the communication,” Downs wrote.

To bolster that claim, Downs cited a 1991 ruling against the Teflon Don. Gotti’s secretly recorded conversations with lawyers were ruled admissible because attorney-client privilege doesn’t cover “communications made for the purpose of committing a crime, regardless of whether the attorney was aware that he was being consulted for that purpose.”

Banks, who retired in 2014, has never been charged with a crime, and Brafman has said his tax case was “resolved with no prosecution.”

In the Rechnitz call, Brafman also said Peralta “is not cooperating,” even though the Manhattan District Attorney’s office wanted him to, the affidavit says.

He knew that because Peralta was repped by lawyer Alex Spiro, then an associate in Brafman’s firm, Downs wrote.

In another affidavit, Downs detailed a March 8, 2015, chat between Rechnitz, his wife and his father, LA developer Robert Rechnitz, during which the dad said he had dinner with Brafman.

“Rechnitz’s father said they were in ‘good shape’ to have ‘Ben on both guys,” meaning that it was good that Brafman represented Banks and Peralta,” Downs wrote.

The FBI also believed the “good shape” remark meant Brafman would help prevent Banks and Peralta from cooperating with law enforcement, Downs added.

From the federal prison in Fort Dix, N.J. where he’s serving a five-year sentence, Peralta on Monday accused Brafman of violating attorney-confidentiality rules on the call.

“Ben was protecting Jona, giving him all the information and finding a plan to throw me under the bus,” he told The Post.

Brafman said Monday that Peralta authorized him to tell Rechnitz he wasn’t cooperating, and Peralta’s claim otherwise was “not true.”

He also called the FBI’s belief that he would keep Peralta and Banks from cooperating “a speculative conclusion ​by agents​,​ with no bas​i​s in fact​.”

Brafman said he’s been acquainted with Robert Rechnitz for more than a decade, and spoke with his son because “I was trying my best to keep [him] from imploding.”

“I felt bad for him because he was a young kid and I was hoping he wouldn’t get in trouble,” he said.

Brafman also said his dinner meeting with the elder Rechnitz involved “trying to convince the father” of the potential peril Jona faced.

“I wanted his father to under​stand that Jona was, in my opinion, headed for legal trouble if he did not stop handing around with all the people he was hanging around with​,” Brafman said.

The FBI’s New York field office didn’t return a message and the Manhattan US Attorney’s Office — which filed Downs’ affidavits in court — declined to comment.

Additional reporting by Kaja Whitehouse