A federal judge this week threw out the conviction of a 66-year-old Long Island man found guilty in 2008 of molesting his granddaughter and two of her friends after defense lawyers investigated a serial number on the back of a photograph that refuted a key portion of the prosecution’s case.

Judge Arthur D. Spatt of Federal District Court in Central Islip, N.Y., ruled on Monday, after five years of litigation in three different courts, that the convicted man, Thomas F. Green of Selden, had been deprived of a fair trial because of ineffective assistance by his lawyer at the time. In a 44-page order, Judge Spatt wrote that the evidence introduced by prosecutors at Mr. Green’s trial in Suffolk County had been poorly investigated by Mr. Green’s defense lawyer and sent the case back to the state court for a new trial.

Mr. Green, a construction contractor, was initially accused of molesting his granddaughter when she was 7 years old, along with four of her friends, each of whom was younger than 10 when the abuse was said to have begun. According to the prosecution, the abuse began in 1998 and continued intermittently for the next few years at Mr. Green’s home during sleepovers and outside the home at local eateries like a Carvel ice cream shop.

The main witness for the prosecution, one of the four friends, identified as B.M., said that she had waited until 2006 to accuse Mr. Green, in part, because she had learned from watching the television show “Law & Order: SVU” that appearing in court was “a big responsibility,” especially for a young girl, according to court records. She said not only that had Mr. Green abused her, but also that she was present when he tried to molest his granddaughter.