Etan, 6, disappeared in May 1979 while walking to catch a school bus near his home in SoHo in Manhattan It was his first time walking to the bus on his own. He had a dollar in his pocket for a soda.

In 1979, Mr. Hernandez was working as a stock clerk at a bodega at West Broadway and Prince Street, near where Etan was last seen alive. In both statements, he said he lured the child through a cellar gate into the basement with the promise of a soda. He said he then strangled him.

Mr. Hernandez said he put the boy, still alive, in a heavy plastic bag, stuffed the bag into a cardboard box and carried it a block and a half away, where he left it in a stairwell on Thompson Street. He said that he went back the next day and that the box had been carted away.

“I don’t know why I did it,” he said toward the end of the interview. “I tried to stop, but I couldn’t stop. My legs were jumping. I was nervous and I did it and I’m sorry I did it.”

Justice Wiley’s decision came without fanfare: Mr. Hernandez sat placidly at the defense table, dressed in an orange prison jumpsuit with his hands cuffed behind him. He stared down at the wood tabletop as if he were not listening. In the audience, Etan’s father, Stan Patz, betrayed little emotion at the news, but leaned over to whisper to an assistant prosecutor who has accompanied him to every court date. Mr. Patz declined to comment as he left the courtroom.

The ruling came about seven weeks after the end of a 10-day suppression hearing in September, at which the judge heard from psychological experts for both the defense and prosecution. Justice Wiley also viewed videotapes of Mr. Hernandez’s initial confession and a second statement he made to a prosecutor.

Mr. Hernandez, of Maple Shade in southern New Jersey, confessed to the killing on May 23, 2012, after a long day of questioning by New York police detectives in a prosecutor’s office in Camden County, N.J.