Cops arrested a turnstile jumper and brought him all the way to a police station — and marched him in front of a desk sergeant — before realizing he was packing a loaded handgun in his waistband, The Post has learned.

Ex-con Billy Walters, 37, slipped through an emergency subway gate at the 149th Street Station without paying the fare around 11:45 a.m. Tuesday, police said.

Cops cuffed him at the scene before taking him to the Transit District 11 substation near Yankee Stadium, authorities said.

The officers did a quick pat-down of the man during the arrest — but somehow didn’t discover the .45 Sig Sauer hanging out of his waistband until they got him in front of the station’s desk sergeant, police said.

A photo obtained by The Post shows a cuffed Walters standing in the station, arms behind his back with his shirt raised in the front and the piece’s handle in plain view.

“While at the police facility, a secondary, more thorough search incidental to lawful arrest was conducted, where an illegal firearm was recovered from the perpetrator,” the NYPD said in a statement.

When Walters was first stopped for farebeating, he allegedly told cops he didn’t pay the transit fee because he was late for a court date.

“I didn’t pay because I was running late to go to court. I got arrested yesterday,” Walters allegedly blabbed to an officer.

He also claimed he had a license for the semiautomatic handgun.

“I have a Pennsylvania license to carry the gun. I carry that gun for protection. Somebody busted my face,” he said, according to an arrest affidavit.

Walters, who is homeless, was charged with criminal possession of a weapon and menacing after police eventually found the gun and determined he did not have a New York City gun license, cops said.

They also found a shopping bag filled with 36 smaller baggies of weed on Walters, and he was additionally charged with possession of marijuana, according to law-enforcement officials.

The NYPD patrol guide states that a frisk should be conducted as soon as a person is taken into custody — with special attention given to the waistband.

Additional reporting by Ben Feuerherd