A Brooklyn man was sentenced to 7 years in prison after pleading guilty to bringing a loaded, unlicensed pistol to Kennedy Airport in April 2015, Queens prosecutors said Thursday.

The weapon was discovered during a routine preflight scanner security check, Queens District Attorney Richard A. Brown said Brown said.

Aquil L. Dunbar, 22, of Bergen Street, pleaded guilty in July to one count of second-degree criminal possession of a weapon, prosecutors said. The charges followed an investigation by Port Authority police.

Authorities said the incident occurred about 3 p.m. on April 24, 2015, at Terminal 5. Brown said security agents discovered a .25 caliber pistol in the carry-on luggage belonging to Dunbar. The gun was loaded with six rounds of ammo, Brown said.

He said it was concealed inside a sock inside a shoe box inside a plastic bag.