There was almost a new sheriff in town on Long Island.

A Long Island man impersonating a police officer tried to take the law into his own hands when he pulled over a van — and found it full of real detectives, police said Saturday.

According to Nassau County police, Valiery Portlock, 25, was driving his black Nissan Sentra on Hicksville Road near Roosevelt Ave in Hicksville at about 11 a.m. on Friday when he drove up behind the van and activated his air horn and emergency lights.

When the van stopped in traffic, the detectives from the Nassau PD’s Electronics Squad got out, identified themselves and tried to approach Portlock’s car.

That’s when the faux cop fled the scene, swerving into oncoming traffic and speeding onto the Long Island Expressway, police said.

Nassau County Highway Patrol spotted him shortly after and pulled him over to make the arrest.

Portlock was charged with criminal impersonation in the first degree, as well as reckless endangerment and unlawful fleeing from a police officer.