A 54-year-old man who spent 14 years in prison for a rape he didn’t commit slapped the city with a federal lawsuit Monday alleging he was done in by false testimony from a Housing Authority detective.

Johnnie O’Neal, of Suffolk County, also names the city Housing Authority detective, Jose Morales, as a defendant in the lawsuit filed in Manhattan federal court Monday and accuses the city of not properly training Morales and other officers on civil rights issues.

O’Neal was convicted of raping a woman at knifepoint on an Upper West Side rooftop in 1984, although he and five relatives said he had been at home watching TV.

The Manhattan DA offered O’Neal a two-year plea deal if he copped to a lesser charge. He refused.

The Legal Aid Society and the DA began re-examining the case six years ago and found that a since-deceased drug addict, Gregory Smith, likely committed the rape and two others.

The DA’s “re investigation confirmed that the lead police officer assigned to the case [Morales] … had lied while testifying during plaintiff’s criminal trial, and in doing so, bolstered the false testimony of the victim and her mother concerning the purported identification of plaintiff as the victim’s assailant,” the suit says.

Manhattan Supreme Court Justice Marcy L. Kahn overturned the conviction in July 2013.

The suit seeks unspecified money damages. The city declined to comment.