A former NYPD sergeant accepted thousands of dollars in bribes from a private investigator in exchange for key confidential information from an FBI database about witnesses in federal criminal cases, prosecutors charged Wednesday.

Ronald Buell, who retired from the NYPD in February, and Joseph Dwyer, a Long Island-based private investigator often retained by court-appointed lawyers, were arrested Wednesday and each charged with bribery, bribery conspiracy and unauthorized access to a federal database.

Dwyer was also slapped with mail fraud charges. Both are expected to be arraigned later Wednesday before a magistrate judge in Manhattan federal court.

Between October 2011 and November 2013, Buell accessed the FBI’s National Crime Information Center database on at least 15 occasions to obtain criminal history and other personal information related to witnesses and others associated with at least 11 criminal prosecutions in Manhattan federal court – which is where Dwyer was paid public funds to be retained as a defense investigator, the feds said.

During the same period, Buell – who now runs a private investigation business – deposited into his personal bank account at least 17 checks totaling roughly $9,000 that were issued by Dwyer’s private firm.

Dwyer, 46, faces up to 45 years in prison. Buell, 48, faces up to 25 years.

Dwyer, through his lawyer, denied any wrongdoing. Neither Buell nor his lawyer could immediately be reached for comment.