Patrolling a Manhattan subway station turned into a battle royale for a lone NYPD cop who was forced to fight off a group of hostile vagrants — one of whom tumbled to the tracks, according to a disturbing new video.

A 47-second clip of the encounter shows the uniformed officer holding a collapsible baton at the ready and repeatedly ordering the men to “stand back” as he backs up along a staircase.

The video — which was shot from behind the cop and posted online — then shows a man in a baseball hat step over another man sprawled on the platform and approach the cop, who kicks him in the leg and knocks him to the floor.

“Stand back! I don’t want to hurt you!” the cop says as two other men approach.

The cop kicks one of those men to the floor, but he immediately pops up and starts throwing punches, which the cop counters with smacks from his baton.

Two other men in tan jackets intervene to stop the violence — with one spreading his arms to hold the assailants back — but a man with shaggy hair ducks under and staggers toward the cop, then stumbles off the platform and lands on the tracks with a thud.

The NYPD said that other cops responded to aid their colleague, who was assigned to a solo post inside the East Broadway station on the Lower East Side.

Several intoxicated, emotionally disturbed men were taken to local hospitals following the incident around 10:30 p.m. Sunday, the NYPD said.

Those men were released following treatment, but cops busted four men caught sleeping on the platform Monday morning on suspicion they were involved in the attack, the NYPD said.

All four were being held at Transit District 4 headquarters in Manhattan with charges pending, the NYPD said.

The cop was dispatched to the west end of the F train platform in response to a complaint that a woman was being harassed by homeless men, according to the Patrolmen’s Benevolent Association.

PBA president Pat Lynch blamed the incident on Mayor Bill de Blasio’s handling of the city’s homeless crisis, saying: “Once again, in de Blasio’s New York, we see a police officer having to rectify a problem allowed to fester by the inaction of this administration.”

Lynch said the unidentified cop “used textbook defensive measures taught in the police academy against overwhelming odds in an effort to protect himself and anyone else on the platform.’

“He is to be commended for good work and courage,” Lynch added.

The scene of the attack is a sticky, foul-smelling area littered with matted cardboard and dozens of empty Budweiser cans and Georgi vodka pint bottles strewn about the tracks.

There’s also a bunch of trash that was shoved through the gate of the locked staircase, including a pair of green men’s underwear and a blue hospital slipper.

A waitress at the JaJaJa Plantas Mexicanas restaurant, adjacent to the station entrance, said she saw authorities haul away a vagrant around 11 p.m. Sunday.

“He was strapped down and wrapped up in bandages, but he was trying to fight them,” said the woman, who gave her name as “Vladi.”

“He was very drunk. Covered in blood.”

Co-worker Johan Morales, 32, of Brooklyn, said he routinely sees around 10 homeless men sleeping in the station at night.

The eatery’s manager, who gave his name as Saul G., also said vagrants “panhandle right here in front of the entrance and we have to ask them to move. They’re pretty aggressive.”

“They come back with hospital tags, whatever. They get arrested for fighting and come back over and over. It’s ridiculous!” he fumed.

De Blasio spokesman Eric Phillips said: “Our police officers are heroes and the Mayor applauds the bravery and professionalism of this officer.”