A Queens senior citizen who shot dead a man who tried to rob him will spend four years in prison after admitting to toting an unlicensed revolver — as his lawyer ripped the city’s “draconian” gun laws.

Charles Foehner, 67, pleaded guilty to one count of criminal weapons possession Thursday in a deal to end his case more than two years after he fatally shot would-be thief Cody Gonzalez, who charged at him near his Kew Gardens home.

The Queens District Attorney’s Office chose not to prosecute Foehner, a retired doorman, for Gonzalez’s killing after he told cops that he’d defended himself from a mugger who lunged at him late at night holding what looked like a knife — but which turned out to be a pen.

Foehner was not charged with manslaughter after claiming self-defense, but pleaded guilty to a lesser gun charge. Brigitte Stelzer

But prosecutors slapped Foehner with a slew of weapons raps for the unlicensed handgun and for an arsenal of illicit handguns, revolvers and rifles inside his home in the quiet neighborhood.

Foehner took the plea deal to avoid a trial, where he faced 25 years in prison on gun charges that are not hard to prove, said his attorney Thomas Kenniff after Thursday’s hearing in Queens Supreme Court.

Kenniff called Foehner a “hero” who was put in an “impossible position” by what he called “draconian” Big Apple gun laws that make it difficult for “law abiding citizens” to obtain permits to carry firearms.

“If this was a state and a city that had its affairs in order, Mr Foehner would be getting a plaque, not a prison sentence,” Kenniff told reporters on the courthouse steps.

Security footage caught the would-be robber charging at Foehner even after the senior citizen pulled a gun.

Lawmakers in New York City and Albany have “repeatedly frustrated the rights of law abiding Americans, New Yorkers, that possess firearms,” added the attorney, who is best known for successfully defending Marine veteran Daniel Penny from charges of fatally choking a homeless man who threatened subway passengers in May 2023.

“If we respected people’s constitutional right, and provided practical means for citizens to exercise that right, Mr. Foehner would not be in the position he is in today,” Kenniff added.

After his arrest for the 2 a.m. killing in a driveway near his home on 82nd Avenue and Queens Boulevard, Foehner told cops he’d been packing the silver revolver to protect himself from Big Apple crime.

Foehner’s lawyer, Thomas Kenniff, criticized what he called the state’s “draconian” gun laws after Foehner struck the plea deal. Brigitte Stelzer

Security footage showed the alleged robber Gonzalez — who had at least 15 arrests dating back to 2004 and a record of mental illness — continuing to charge at Foehner even after the senior pulled his gun.

Foehner took the deal Thursday with the understanding that he’d be sentenced to four years in prison at his sentencing date Jan. 14, his lawyer said.

Until then, he’ll remain “at liberty” and will be able to celebrate Christmas with his wife, Judge Toni Cimino ruled — over objections from the Queens DA’s office, which had pushed for him to spend the holidays at Rikers Island.

“While we very much respect DA Melinda Katz and the fine prosecutors she assigned to this case, we were disappointed that the DA’s office sought to have Charlie remanded before sentencing,” Kenniff, of the firm Raiser Kenniff & Lonstein, said Thursday.

“We are grateful that Judge Toni Cimino agreed to let Charlie rejoice with his wife in the light of this Christmas season before he begins his sentence.”