An NYPD officer who provided security for the wife of El Chapo was busted for dealing cocaine and acting as security for other dealers in Queens, sources said Wednesday.

Officer Ishmael Bailey, 36, escorted the wife of the notorious drug kingpin, Emma Coronel Aispuro, to Joaquín “El Chapo” Guzmán’s sentencing in Brooklyn federal court in July, law enforcement sources told The Post.

The officer could be seen wearing a black suit and dark sunglasses as Aispuro exited the back-passenger door of a black SUV, according to video of the scene.

Aispuro was a mainstay at her husband’s drug trafficking trial, showing up to the courtroom every day of the trial in chic clothing and designer sunglasses.

Bailey was nabbed Wednesday on charges of conspiracy and sale of a controlled substance for allegedly acting as security twice when a load of cocaine was transported from various locations around Queens.

Bailey — who was arrested by officers with the NYPD’s Internal Affairs Bureau and the Queens District Attorney’s office — was also charged with possession of a controlled substance, bribe receiving and official misconduct.

During his arraignment Wednesday night in Queens Criminal Court, Assistant District Attorney Karlton Jarrett revealed that prosecutors “alleged [Bailey] provided security for El Chapo’s wife during El Chapo’s [drug-trafficking] trial,” which took place this year in Brooklyn federal court.”

Bailey did his stint as security for the drug lord’s wife in addition to his job in the NYPD, law enforcement sources said.

It’s unclear who paid him for the trial security detail, but IAB investigators began probing him when they noticed him providing the security, the sources said.

Bailey wept at his brief arraignment as a judge ordered him held on $50,000 bond and $25,000 cash bail.

Prosecutors say that on Aug. 27, the 12-year veteran met with an undercover cop who was posing as a drug dealer and allegedly agreed to act as security as cocaine was moved around the borough, according to prosecutors.

The next week on Sept. 4, Bailey met with the same “dealer” in Astoria, where he allegedly held open a black and red duffel bag as three packages – one a kilo of cocaine and two fakes – were placed inside.

Bailey was paid $2,500 and the bag was transported to a parking lot in College Point, Queens, where another undercover officer took the bag, prosecutors said.

Again on Sept. 12, Bailey allegedly provided his security services for cash.

On that day he met with the same undercover cop in Astoria and was given $10,000 to pick up two kilos of cocaine from a location in Maspeth, Queens, according to prosecutors.

If convicted, he faces up to 15 years behind bars.

Additional reporting by Craig McCarthy, Natalie Musumeci and Ben Feuerherd