A Brooklyn prosecutor was caught having an affair with one of the NYPD cops accused of raping a handcuffed teenager, The Post has learned.

Assistant District Attorney Nicole Manini, 34, is under investigation for potentially violating professional conduct rules for New York lawyers, according to sources familiar with the matter.

Manini’s illicit relationship with now-former Detective Richard Hall, 33, was uncovered when investigators with her office reviewed his cellphone records as part of the rape case, sources said.

The phone logs revealed multiple calls between Manini and Hall, who is married with two kids, sources said.

The calls began before the alleged Sept. 15 rape and continued afterward, sources said.

The DA’s office referred Manini for investigation to the court system’s Grievance Committee for the Second, Eleventh and Thirteenth Judicial Districts, which prosecutes cases of professional misconduct by lawyers.

“During our investigation of this case, we learned that a junior assistant district attorney in our office was engaged in an intimate relationship with defendant Hall and knew [second] defendant [Eddie] Martins socially,’’ a spokesman for the DA’s office told The Post Monday.

“This ADA had no involvement in or access to the investigation or prosecution,’’ the rep said. “Out of an abundance of caution, we have disclosed this information to all relevant parties.”

Michael David, the lawyer representing Hall’s rape accuser, said he plans to use the former cop’s affair with Manini in his client’s pending civil rights suit against Hall, Martins and the city.

“It’s completely relevant to this case. It goes to [Hall’s] credibility,” David said.

Hall and his former partner, Martins, are accused in a 50-count indictment of raping and sexually abusing the 18-year-old woman inside an NYPD van after she was picked up in Calvert Vaux Park for allegedly having illegal prescription pills.

Hall is accused of watching in the rear-view mirror as Martins allegedly raped the woman. Hall then allegedly forced her to perform oral sex on him.

The cops — who claim the entire incident was consensual — quit amid the allegations, which DA Eric Gonzalez has called “conduct that boggles the mind.”

Manini, who received her law license in 2012, previously worked as a defense and family court lawyer in New York City and as a correction officer in Lehigh County, Pa., according to her LinkedIn profile. She was hired by the DA’s Office in 2015 and is paid an annual base salary of $65,000, payroll records show.

Manini didn’t immediately return a message seeking comment. Hall’s lawyer, Peter Guadagnino, declined to comment.

Additional reporting by Nick Fugallo