Authorities said Wednesday that three homeless men who battled a New York City police officer on a subway platform will face criminal charges after video of the encounter garnered millions of views online.

Two of the men will be charged with riot and obstructing governmental administration, police said, while a third man faces those counts in addition to attempted assault, attempted criminal possession of a weapon and menacing. Two of the three men had been taken into custody Wednesday evening. The third remained at large.

Two other men in the video, who appeared to be trying to break up the scuffle, aren't facing charges.

The charges stem from an incident in which a group of homeless men refused a police officer's orders to "stand back."

Footage of the encounter, viewed more than 4.75 million times on social media, showed Officer Syed Ali using a baton and kicking at the men, who appeared to be drunk, as they come at him one at a time Sunday night. Ali, an Army veteran who served in Iraq and Afghanistan, never pulled his gun.

Police cited the men the following day for sleeping on the station floor but not for the altercation. The Manhattan District Attorney's dropped that case, citing a policy curbing prosecution of those kinds of low-level violations.

But as the video got more and more attention, the decision not to pursue the case drew criticism from Ali's union, the Patrolmen's Benevolent Association, which said the men "should be held accountable for their actions." The DA's office said prosecutors who declined to move forward on the sleeping-related violations were not aware the men also were involved in an altercation with the officer.

"There is no telling how much damage these mopes would have done to that courageous police officer had he not been equipped to handle them," union president Patrick Lynch said in a statement.

One of the homeless men tumbled off the platform in the chaos and had to be pulled from the tracks. He and the others were taken to a hospital for treatment.

The men weren't arrested until the next morning, when police spotted them back at the East Broadway station and cited them for sleeping on the floor.

"When people are arrested for attacking officers, we prosecute them," said Danny Frost, a spokesman for the DA's office. "These men were not arrested for attacking an officer, they were arrested for sleeping on the floor of a subway station — a rules violation, not a crime."

Mayor Bill de Blasio praised Ali's "extraordinary professionalism and bravery." He tweeted Tuesday that "attacking our men and women in uniform won't ever be tolerated."