An NYPD detective testified Thursday that the risk of an ambush in stairwells of the housing project where police said a rookie cop accidentally shot an unarmed man makes them among the city’s most dangerous areas to patrol.

The testimony of Det. Nathan Garcia came on the fourth day of Officer Peter Liang’s manslaughter trial in the shooting death Akai Gurley, 28, inside a darkened stairwell of the Louis H. Pink housing projects on the night of Nov. 20, 2014.

In other testimony Thursday, a lieutenant on the scene shortly after the shooting, said Liang appeared stunned and confused and unable to stand on his own.

If convicted, Liang faces a maximum sentence of 5 to 15 years in prison. He pleaded not guilty in February of last year.

Prosecutors called Garcia, who works at the police academy updating curriculum, to question him about the training of NYPD recruits.

Garcia told Brooklyn jurors that when he worked the Pink Houses, he remembers being “trained to be cautious and be concerned for possible ambushes.”

However, under cross examination from Liang’s defense attorney Robert Brown, Garcia said his supervisors in the field trained him to always keep his gun out while patrolling stairwells inside the Linden Boulevard complex in the event of an ambush.

advertisement | advertise on newsday

That field training, taught by supervising officers, is not part of academy curriculum, Garcia said.

Liang, his gun in one hand and a flashlight in the other, opened the eighth-floor stairwell door when his weapon discharged.

A bullet struck Gurly in the chest as he and his girlfriend were on the seventh floor landing, police said. Rescuers transported Gurley to a hospital where he was pronounced dead.

Lt. Vitaliy Zelekov testified that when he arrived to the shooting scene, Liang looked “shocked’’ and “incoherent . . . He appeared shaken, distraught and was hyperventilating. I had to ask another officer to stay with him.”

Zelekov said when he came upon the scene Liang “was frozen.”

@Newsday

The lieutenant testified he even called an ambulance for the dazed rookie cop.

“He couldn’t stand on his feet,” Zelekov said.

Judge Danny Chun asked him: “When you use the word frozen what do you mean?”

Zelekov responded: “He was standing staring up into space.”