Riders fled in terror to opposite ends of a stopped subway car when at least one NYPD cop was seen pointing his pistol toward a window from the platform in a Brooklyn station, a video posted online shows.

“Oh, he’s got a gun!” one woman exclaimed as the frightened passengers scurried away.

But when the doors to the train car remained closed, one man remained calmly seated on a bench facing the platform with his hands raised, the video posted on Twitter shows.

Once the doors opened, two uniformed cops rushed in and forced him to the floor.

Several other cops quickly followed, including one who holstered his weapon inside the car.

The 2-minute, 20-second video went viral and racked up more than 3 million views by Monday afternoon after being posted on Friday afternoon.

“In case you’re wondering how an arrest in NYC goes down,” wrote Elad Nehorai, who posted the clip. “The guy has made absolutely no indication that he would flee or fight and wasn’t trying to hide.”

The NYPD defended the cop who drew his gun, with a spokesman saying that the suspect — identified as Adrian Napier, 19 — was believed to be armed and that protocol called for such persons to be arrested “at gunpoint.”

Cops had earlier chased Napier into the Pacific Street subway station in response to witness reports that he was brandishing a gun near Atlantic and Flatbush avenues, the NYPD said.

Napier jumped over a turnstile and hopped onto a southbound 4 train that was later stopped at Franklin Street, the NYPD said.

No gun was found on Napier, who law enforcement sources said is a member of the Crips street gang with a rap sheet listing 14 arrests on charges including assault, robbery and grand larceny.

Napier was charged with theft of services and taken into custody for questioning in a larceny case, the NYPD said.