An NYPD detective was sentenced to two years in prison on Friday for lying to the feds to protect his sports bookie — who was allegedly dealing drugs while working as a government informant.

Saed Rabah, 46, pleaded guilty in December 2018 to one count of obstruction of justice in White Plains federal court for giving federal investigators a bogus phone number for his informant in September 2016.

The informant, Rabah’s bookie, was being investigated for dealing MDMA and prescription pills.

The detective’s subterfuge was not successful, as investigators eventually were able to locate the dealer’s actual number.

After obtaining a wiretap for the cellphone, they found text messages that showed Rabah chatting with the bookie about placing bets and scoring MDMA and marijuana-laced baked goods.

The cop also allegedly shared in profits from the man’s illegal sports-betting business — for which he helped attract bettors, according to court papers.

Rabah, who served in the department for 20 years, retired one month prior to giving the wrong number to investigators.

“As an NYPD detective, Saed Rabah’s first duty was to uphold the law, not befriend known drug dealers and assist in their criminal enterprises,” US Attorney Geoffrey Berman said in a statement.

“Now Rabah, a convicted corrupt former police officer, will serve time alongside criminals he and his colleagues arrested.”

Rabah had faced up to 20 years in prison.