Repeat gun felon Andrew James could have gone to prison for up to 15 years for the loaded gun he got caught with while driving through Queens two years ago.

Instead, the charges against him were dropped and the city has awarded him an astonishing $33,500 settlement, The Post has learned — after video showed cops had found the gun during an unauthorized search of his car.

The big payday settles James’ $3 million civil-rights lawsuit.

James, of Valley Stream, LI, was pulled over for crossing a double yellow line in March 2012 by plainclothes officers Andrew Torres, Jason Forgione and James Phillips, according to court ­papers.

The officers claimed to smell marijuana in his white Cadillac Escalade and searched it, finding $10,000 in cash, a small knife and a police scanner, sources said.

Torres hauled James off to a police precinct, while Forgione and Phillips peeked under the hood of the car, finding a loaded .40 caliber Smith & Wesson handgun wrapped in a pillowcase, according to court papers.

But realizing that the search might have been illegal, the three cops concocted a story that they’d found the gun while impounding the SUV at the station house as required by law — a claim later disproved by a video a neighbor had taken of the incident.