A Brooklyn judge on Thursday declined to throw out the 20-year-old murder conviction of a man who claims disgraced ex-NYPD Det. Louis Scarcella framed him.

Brooklyn Supreme Court Judge Shawndya Simpson said the Brooklyn District Attorney proved its case that Nelson Cruz, 38, murdered Trevor Vieira in East New York in 1998.

“The defense has not proved the defendant is innocent by preponderance of the evidence,” Simpson said, as Cruz’s relatives in the courtroom sobbed.

But Simpson — who had already previously rejected an effort by Cruz to vacate his conviction and given him another shot — then took the unusual step of giving Cruz’s lawyers a second chance to re-argue their case.

Simpson said she would hold a Dec. 16 hearing on the matter.

Scarcella — a star homicide detective in some of the most crime-ridden areas of Brooklyn in the 1980s and ’90s — has been linked to 14 cases in which convictions were later tossed out, eight of which with the support of the Brooklyn DA’s Conviction Review Unit.

But the DA’s office opposes throwing out Cruz’s conviction, with a spokesman saying Thursday: “We agree with the ruling.”

Cruz — who is serving a sentence of 25 years to life — had just turned 17 when he was collared for Vieira’s murder. He claimed Scarcella and his then-partner, Stephen Chmil, forced him to sign a false confession and then got a witness to lie that Cruz was the shooter.

“The only witness against Nelson Cruz says the police told him that Nelson Cruz did it, and they needed him,” Justin Bonus, Cruz’s attorney, said to the judge after her ruling.

Bonus alleges that witness, Eduardo Rodriguez, was the real killer — and that five others witnesses have since come forward to corroborate Cruz’s innocence.

Put on the stand earlier this year, both Scarcella and Chiml claimed they don’t recall certain facts about the Cruz case — but Scarcella said he stands by all his convictions “110 percent.”

Among those who joined Cruz’s family in the courtroom Thursday was Derrick Hamilton, whose 1997 murder conviction was also tied to Scarcella and tossed out two decades later.