The NYPD officer accused of manslaughter in the 2014 shooting of an unarmed man in a public housing stairwell choked back tears on Monday as he told jurors in Brooklyn Supreme Court that his gun fired by accident and he panicked afterward.

Peter Liang said he drew his gun as he entered a dark stairwell at the Louis Pink houses because he sensed possible danger heading to the roof, but did not put his finger on the trigger. When he stepped onto the 8th floor landing, he said, he heard something.

“It was a quick sound. It startled me,” Liang testified. “The gun just went off when I tensed up.”

The rookie officer, 28, said he initially didn’t realize anyone had been hurt, and went into the hallway on the 8th floor to discuss calling in the discharge with his partner. When he went back into the stairwell to look for the bullet, Liang said, he heard someone crying on the 5th floor.

When he found Akai Gurley on the floor dying with his girlfriend bent over him, Liang said, his reaction was, “Oh my God, I’ve shot someone.”

At that point in his testimony, Liang turned his back to the courtroom and began sobbing. He was unable to continue, and the judge let him leave the courtroom to compose himself. He returned to the courtroom after 60 seconds, but had to turn away two other times.

Liang said that Gurley “looked like he was seriously injured,” explaining, “His eyes were rolled back. He was just laying there very still.”

He said he asked for the address of the building so he could radio for help, but was in a state of “shock and disbelief” about what happened. “I was just panicking so much, I couldn’t process it in my head,” Liang testified, so he went to the 4th floor to get the address from a neighbor who was calling 911.

The officer said that, although he had received CPR training at the police academy, he never got to work on a mannequin and instructors gave recruits most of the answers on tests. He thought, he said, that using his radio to try to get “professional medical help” was the best way to aid Gurley.

Prosecutors have charged Liang with manslaughter and criminally negligent homicide for the shooting, and official misconduct for his failure to render aid to Gurley after he was shot. He has been on modified administrative duty since it happened.

The defense and prosecution both rested their cases after Liang’s testimony, and closing arguments are scheduled for Tuesday.

After Liang’s testimony, family and friends of Gurley called for a conviction during a brief news conference. Gurley’s mother Sylvia Palmer called the officer’s testimony “horrible.”

“Peter Liang walked away and left Akai to die in his own blood,” she said. “…. Police officer Peter Liang said that it was an accident, an accidental death. Peter Liang, my son’s death was no accident. You murdered my son. I need justice for my son.”