A Keene man who police alleged shot a gun inside a Mechanic Street apartment earlier this year has pleaded guilty to firearm possession as a felon.

John Whalen, 43, was sentenced last week in Cheshire County Superior Court to between one and seven years in state prison for that conviction, also a felony. Whalen, who used to live in Greenfield, Mass., was previously found guilty in Massachusetts of crimes related to possessing illicit drugs, court filings show.

Local prosecutors had accused him of firing a single shot through the floor of a second-story apartment at 23 Mechanic St. and into an unoccupied bed downstairs. Police said multiple other people were in the upstairs unit when the Oct. 23 incident occurred.

Whalen was also charged with reckless conduct with a deadly weapon, but prosecutors dropped that charge as part of his plea deal.

The tenants living in the downstairs Mechanic Street apartment weren’t home when Whalen fired the gun but reported the incident later that night, according to an affidavit filed in court by Keene police Detective Jennifer Truman. Two people who were upstairs with Whalen told police afterward that he’d been saying the gun didn’t work right before he shot it, Truman wrote.

Whalen was arrested Oct. 29 and was held in jail until his sentencing because a Superior Court judge found last month that his release would endanger either him or the public. His prison term will be reduced by the 54 days he already spent in jail.

Caleb Symons can be reached at 352-1234, extension 1420, or Follow him on Twitter @CalebSymonsKS.