A 16-year-old was busted with a loaded .38-caliber pistol in his backpack at a Queens high school Thursday morning, police said.

The student, whose name wasn’t released because he’s a juvenile, was walking through the metal detectors at John Adams High School in South Ozone Park around 9:30 a.m. when the machine activated, cops said.

School security found the loaded pistol and an unknown quantity of pot on him, officials said.

He’s charged with criminal possession of a weapon and possession of marijuana, police said.