An illegal immigrant whose genetic material was allegedly found on a dead New Jersey prostitute will walk free on murder charges — all because police wrongfully obtained his DNA and a judge wouldn’t let them take another sample, according to local reports.

Still, Guatemalan national Rafael Camey is expected to be deported Tuesday following the decision in a Passaic court to drop charges against him, the Bergen Record reports. He’d been detained for more than five years as the case progressed.

Prosecutors allege Camey, 38, raped and murdered Rutherford prostitute Karen Splettstoesser, 50, whose body was found behind a Passaic supermarket with Camey’s DNA in 2013.

The officers at the time informed Camey of his Miranda rights in his native Spanish but had him sign a consent form to give his DNA, collected via a mouth swab, in English without translation.

A trial court previously determined that the DNA sample, the main evidence against Camey in the case, was collected unlawfully.

The court criticized the local police department’s “little use of legal process” and ”shocking” failure to interview Camey’s roommates or co-workers about his whereabouts that night — or obtain a warrant to check the home of Splettstoesser’s husband, who had been arrested for an alleged act of domestic violence against her.

The prosecution in Superior Court on Monday said the state would dismiss the case entirely following the previous trial, as well as Judge Sohail Mohammed’s decision to not allow the state to take a second sample, according to the Bergen Record.

Mohammed’s decision to decline a second swabbing was based on new standards set by the Supreme Court that the state must show “clear and convincing evidence” that the initial swabbing “was not the result of flagrant police misconduct.”

Senior Assistant Prosecutor Seth Galkin told the Record that his team “didn’t feel an appeal would be successful.”

Members of Splettstoesser’s family were furious with investigators and the justice system for failing them.

“It’s definitely devastating and it’s frustrating. I still thought there was hope, up until now — and no, there’s not,” said Nicki Philbern, 37, Splettstoesser’s daughter.

“And it falls back on the police department, the investigation, the way it was conducted so poorly. And that’s where my frustration lies — with them,” she continued. “These are supposed to be trusted people with experience.”

Jeremy Clark said even if Camey is deported back to Guatemala, he still represents “a danger to whomever he’s around.”

“It’s just sad,” Clark, 41, said. “The way I understand, everything is leaning towards him being the one who did it. So for him to get off because of something the police did wrong — it’s just pretty sad that he’s more than likely guilty and he’s getting off scot-free.”