A plainclothes officer can be seen on video repeatedly punching a man after he was taken to the ground, following what NYPD officials said was a violent and random attack on officers in a nearby station.

Police officials said the shirtless man walked into the 50th Precinct station house in Kingsbridge, the Bronx, around 1 p.m. on Thursday, punched two female officers and then fled the building. A 31-year-old officer was punched in the back, while a 51-year-old officer was punched in the head and suffered a bruise, police said.

The man was caught about two blocks away on 238th Street, authorities said. As officers moved to arrest him, he punched a 28-year-old officer in the head, leaving that officer with lacerations to his right hand and pain in his left knee and right elbow, police said.

The footage, which circulated widely on social media, shows a man police identified as Wilton Pena, 36, of Mott Haven, trading punches with another man the NYPD said is a police officer. The shirtless man fled before falling down. The officer then straddled the man and repeatedly punched him in the head on the sidewalk as more officers surrounded him. Police said the video captures the man being taken into custody after the station house assault.

NYPD officials said Pena was released from the hospital Thursday and taken to central booking where he was charged with six counts of assault, three counts of menacing, three counts of disorderly conduct and three counts of harassment, according to police.

As of Friday evening, Pena’s information had not been made public in court records, and information about his attorney was not immediately available.