NEW YORK — An undercover police detective accused of punching out an SUV window during a motorcycle rally that descended into violence was unmasked Wednesday in a courtroom where he was confronted with serious assault charges.

But Detective Wojciech Braszczok’s lawyer insisted he would be exonerated by the very video prosecutors say incriminates him in the Sept. 29 melee.

“The allegation is that he struck the rear portion hatchback window, which has a gaping hole already in it; it’s already destroyed,” attorney John Arlia said. “Under the law, it’s a fatal flaw. You can’t break what’s already broken.”

Arlia said the video clearly shows Braszczok didn’t participate in the eventual attack on the SUV driver and was nowhere near him. Braszczok hasn’t been charged with assaulting the driver, Alexian Lien, who authorities say was pulled from his Range Rover and beaten on the street by other motorcyclists.

Braszczok, who appeared in court sporting a beard and wearing a hooded sweatshirt and camouflage pants, was charged with assault and criminal mischief.

Cameras were barred in the courtroom because Braszczok’s lawyer said his safety would be jeopardized. Braszczok hid his face in his hood when he left court after posting bond.

Braszczok, a married father of two, has been on the job for a decade. He has worked in the New York Police Department’s intelligence division, quietly infiltrating and investigating. His lawyer said he has served “valiantly.”

But prosecutors said Braszczok was an active participant in the attack.

Braszczok was off duty when he joined the rally of more than 1,000 motorcyclists. Police say the bloody encounter was touched off when a motorcyclist and Lien’s SUV bumped. Video captured at the scene shows riders swarming around the SUV before the driver takes off, running over and seriously injuring biker Edwin Mieses Jr.

Bikers gave chase up Manhattan’s West Side Highway, caught up with the SUV, smashed the driver’s side window and dragged Lien out, authorities say.

Braszczok did nothing to stop the assault, prosecutors said. He didn’t call 911 and didn’t report it to his superiors for two days, and then when he did he lied about it, Assistant District Attorney Samantha Turino said. At first Braszczok told investigators he didn’t see the attack, then changed his story to say he saw it but didn’t participate, she said.