An NYPD detective testified Wednesday at the trial of a man charged with causing Nassau Police Officer Joseph Olivieri Jr.’s death about the desperate moments that unfolded after a vehicle hit the victim as he worked at a Long Island Expressway crash scene.

Det. Edward Wilson, 43, who was then off-duty and had just been in a wreck, said he was a short distance away from Olivieri on that early morning in October 2012 when he first heard a vehicle approaching and then an impact.

Wilson said he turned in Olivieri’s direction and saw a black vehicle and a Toyota Camry — the car he’d collided with minutes earlier — coming to a stop near the median.

OpinionOpinion: Are you a drunken driver if you stop driving?

“I kind of stood there for a second dazed . . . at which point I heard someone say, ‘Where’s the officer? Where’s the cop?’” he said.

Wilson testified in a Mineola courtroom that he went running over and found Olivieri lying facedown on the ground.

“His body was twisted around,” he said. “. . . One of his boots was missing and he was motionless.”

advertisement | advertise on newsday

Wilson said he reacted by grabbing the Nassau officer’s radio from his belt and using it to call in “officer down.”

“Within seconds, another highway unit responded,” the detective testified. “He got out of the car and he saw Officer Olivieri on the ground and he just started losing his composure . . . He was clearly upset. He kept yelling, ‘Joe!’ ”

Motorist James Ryan, 28, of Oakdale, is on trial for charges including aggravated vehicular homicide in Olivieri’s death.

Prosecutors say Ryan’s reckless actions in the early morning of Oct. 18, 2012, caused Olivieri’s death because it was Ryan’s drunken driving that brought Olivieri to the scene of two crashes before a different driver hit and killed Olivieri. The officer was standing by Ryan’s Camry in the HOV lane when he was run down.

Prosecutors say Ryan was speeding home from a Manhattan lounge where he’d been drinking vodka when he first crashed into a BMW near Exit 35 in North Hills.

Ryan fled, but slammed on his brakes in traffic a short distance east, and caused Wilson’s Honda Civic to hit the back of Ryan’s Camry, according to authorities.

Minutes later, the driver of a black Cadillac Escalade struck and fatally injured Olivieri, according to prosecutors, who say that motorist was “rubbernecking.”

At 40 mph, that driver didn’t see anything in the HOV lane until the last moment, when he swerved and hit his brakes, authorities said.

advertisement | advertise on newsday

The district attorney’s office decided the Escalade driver’s actions weren’t criminal and he got immunity after testifying before a grand jury.

However, Ryan’s Mineola attorneys, Marc Gann and Zeena Abdi, say the Escalade driver is responsible for Olivieri’s death and what happened actually was three separate accidents.

Olivieri came upon the accident scene while responding to a call for a flat tire, police said at the time. When the officer arrived, he parked near Wilson’s Honda Civic in the right lane of the eastbound LIE, police said.

Wilson testified Wednesday that he then told Olivieri that he believed Ryan was intoxicated. He told prosecutor Maureen McCormick that Ryan had been ranting about the damage to his own car after their collision, and that Ryan was a little unsteady on his feet. After the conversation, Olivieri crossed the expressway to check on Ryan and was then hit.

The trial continues Thursday, when the Escalade driver could be called to testify.