The judge found inaccuracies with the dates on evidence corroborating the testimony of some of the girls’ accusations.

At trial, prosecutors claimed Green molested five girls in both public and private places between 1998 and 2003.

One girl claimed she slept at Green’s home every weekend and every day during the summer of 1998 when she was 7, and one night, she and another girl watched a scary movie with Green and they decided to sleep in bed with him after they were frightened by the movie. The girl claimed during the night, she woke up to find Green performing a sex act on her, according to court documents.

The girl also alleged that Green forced her to perform other sex acts and committed violent abuse against her, according to documents. The girl claimed at trial that she and her friend made a pinky swear that they would tell someone about the incidents when they got older and were “ready to face” what had happened, documents said.

But one of the girls denied that any of the acts of abuse had happened to her, or that she even knew the girl making the allegations, according to court papers.

A photo of the girls together marked “Coney Island 6/98” was shown at trial, but defense attorneys said in court that the film used for the photo was not even being manufactured in 1998, according to documents.

In a 44-page opinion, Spatt said Green’s trial attorney, Paul Gianelli, should have challenged the physical evidence presented by prosecutors more closely.

Suffolk County prosecutors were appealing the judge’s ruling before deciding whether to retry Green.

Green, who was known as “Grandpa” on his Selden block, served five years of a 35-year prison sentence for molesting neighborhood children before his conviction was thrown out.

“Thomas Green should have spent this past five years surrounded by loving friends and family,” Kuby said in a statement. “Because of the misconduct of the Suffolk County DA’s office, he spent those years in prison as his cancer, untreated and undetected, metastasized. In their self-righteous zeal, the prosecutors killed an innocent man and remain both unapologetic and unaccountable.”

A spokesman for the district attorney’s office did not immediately comment.