A former Metropolitan Detention Center corrections officer accused of raping a female inmate is getting a new trial because prosecutors failed to turn over evidence that could potentially have exonerated him, according to court papers.

A jury convicted ex-guard Carlos Martinez in January 2018 of aggravated sexual abuse, sexual abuse of a ward, and other charges for the repeated rape of a woman identified in court as “Maria.”

The ex-guard was arrested alongside two other officers who were accused of sexually assaulting female inmates at the MDC — including Eugenio Perez, who was identified due to his distinctive, hooked-shaped penis. Perez was convicted at trial and is awaiting sentencing.

But now Brooklyn federal Judge Edward Korman has ordered a new trial for Martinez, based on the statements of another inmate identified as “Jane Doe #4” that he says differ markedly from the accuser’s trial testimony and recast “the key factual issue at trial: whether the relationship between Maria and Martinez was consensual.”

“Jane Doe’s testimony may not inexorably lead to an acquittal in this case,” Korman writes in his July 2 decision. “But even if the suppressed evidence does not mandate acquittal, it raises a reasonable probability of a different outcome.”

Doe told investigators that Maria avoided interactions with prison staff that could reveal her relationship with 49-year-old Martinez, and would create scenarios in which she could be alone with him, the documents say.

While Martinez’s conviction stands on charges of sexual abuse of a ward — given that Maria was an inmate and therefore incapable of consent — he will be retried on the aggravated sexual abuse and sexual abuse charges.

The US Attorney’s Office declined to comment.