A New Jersey man accused of the murder of 6-year-old Etan Patz in 1979 calmly confessed on a videotape played in court on Monday to choking the boy and stuffing him alive in a garbage bag he tossed in an alley.

A Manhattan judge will decide whether the confession taped by police in 2012 will be allowed as evidence against Pedro Hernandez, who is accused of kidnap and murder.

Patz disappeared on his way to school on May 25, 1979, near his home in Manhattan’s SoHo neighborhood. It was the first time he had been allowed to walk alone to a school bus stop.

The search for the boy gripped the city. Patz was one of the first children pictured on the side of milk cartons as part of an appeal for information on missing children.

Hernandez’s defense attorney argues his client does not understand his legal rights. The attorney, Harvey Fishbein, said Hernandez suffered from mental illness including hallucinations and was borderline mentally handicapped.

In the confession, Hernandez, 53, described luring the boy into a SoHo deli where he worked with the offer of a cold soda.

The tape was played in state Supreme Court before Justice Maxwell Wiley. It was the first time it had been shown in public.

Patz’ parents were in court, although his mother left before the video was shown.

Hernandez said he took Patz to the basement and strangled him.

“I grabbed him by the neck and started to choke him. I was nervous, my legs were jumping and wanted to let go but I couldn’t let go,” Hernandez said. “It was like something took over me.”

Hernandez said the boy fell to the floor and that he knew he was still alive because he was gasping and his legs were moving.

He said he put the boy in a garbage bag, which he put in a box and carried on his shoulder to an alley a couple blocks away.

He said he left the box in the alley and went back to work. When he returned the next day, he said the box was gone.

Patz’s body was never found, but he was legally declared dead in 2001.

‘WASN’T THINKING RIGHT’

On the videotape, Hernandez spoke softly and calmly without any apparent emotion.

“Mentally I was like, I feel bad and I don’t feel bad. Half and half,” he said. “I wasn’t really thinking right at the time.”

In court, clad in an orange jumpsuit, Hernandez also betrayed no feelings.

He offered differing recollections on the tape of what he had intended when he approached Patz on the sidewalk.

At one point, he indicated he did not have any violent intentions, but said later under police questioning: “My mind was already made up what I was going to do.”

He told police he had been diagnosed with manic depression and schizophrenia.

His lawyer argued Hernandez was questioned for several hours before police read him his rights and made the videotape, which he said was filled with “the impossible” and “the highly improbable.”

The hearing was set to resume on Tuesday and expected to take several weeks.

Police got a tip about Hernandez, who was living in Maple Shade, New Jersey, a month after authorities in April 2012 excavated the basement in another SoHo building, which failed to yield clues.

The tip said Hernandez told family members as far back as 1981 he had killed a child in New York, police said.