An undercover cop on trial in the biker gang assault of a Manhattan dad said he thought victim Alexian Lien was the bad guy after the motorist ran over a motorcycle rider while trying to get his wife and child away from the swarm of bikers.

But Det. Wojciech Braszczok admitted he should have helped Lien as he was being beaten by the bikers.

“I thought he was the aggressor,” said Wojciech Braszczok, who was caught on video smashing the back of Lien’s Range Rover, then doing nothing as his fellow bikers beat the Tribeca dad.

“He took off and fled the scene,” Braszczok told Justice Maxwell Wiley at the non-jury trial. “I was going to get off the bike and go to the driver’s side door and tell him to stop. Tell him he has to turn the car off. He just ran someone over.”

Lien was driving on the West Side Highway Sept. 29, 2013 whern his SUV was surrounded by the bikers. In a bid to escape he ran over and injured one of them.

Braszczok said he joined the pursuit of Lien as a “civilian” using “police tactics.” But he admitted he got caught up in the moment.

“It wasn’t intentional. I felt threatened,” he told the judge.

“I did hit the glass and kicked the car. It’s a reaction. It wasn’t intentional. I never meant to. I just wanted to keep the car from getting away. Something came out of me. Something. I don’t know what it was.”

On cross examination, prosecutor Joshua Steinglass chipped away at Braszczok’s claims.

“Did you do a single thing to help this guy?” Steinglass asked.

“No,” Braszczok answered.

He said he left the scene, feeling it was unsafe, even as he saw Lien being beaten. “I’m appalled. I can’t believe the situation escalated to that point,” he said.

“I wish I could have done more to help him,” Braszczok said. “I made the decision that it was unsafe for me.”

Down the block he shouted at a passerby to call the police. “I should have called 911, but I didn’t. I’m embarrassed by my reaction,” Braszczok testified.

Braszczok said he lied to his supervisors about not being at the scene because, “I was basically scared that I was going to get fired.”

“At the same time that he’s being stomped on and kicked and he’s being struck in head with helmets are you telling us you didn’t see that when you looked over?” Steinglass asked, adding: “Is that what you’re trained to do as a police officer? Run?”

“If you feel unsafe, yes,” Braszczock answered.

Nine other bikers arrested pleaded guilty. Braszczok, 34, and co-defendant Robert Sims, 36, decided to go to trial on charges of gang assault.

Regarding the detective’s claim that he fled out of fear, a law enforcement source told the Post: “Cops don’t run. They may have to back up, shield themselves, take cover, do 10 different things not to become a victim themselves. But cops don’t run from the scene. That’s complete bull—t.”

“From the onset of this incident, he should have dialed 911, stayed on the scene, and directed responding officers to the people that were committing the crime. He should have been a defacto witness. He was definitely off-base running. He should have remained at the scene at a safe distance so he could observe and help responding officers identify people who were committing the crime. “

Additional reporting by Shawn Cohen