He was spotted at school with an e-cigarette. What cops found in his backpack was worse.

A 14-year-old Hallandale High School student was arrested and charged with possession of a weapon on a school campus and perjury Tuesday after police say they found a loaded pellet gun in his backpack.

How they found it, cops say: Administration spotted him smoking an e-cigarette in the hallway and alerted a school resource officer, who checked his bag.

“The search revealed what appeared to be a loaded .38 revolver in the front pocket of his book bag,” police said in an email.

The discovery at about 1:15 p.m. Tuesday led to the school, located at 720 NW Ninth Ave., being placed on a Code Red lockdown for nearly two hours while police searched the school for more weapons. No other weapons were found, police said.

Police determined the “weapon was a pellet gun with five pellet rounds and one real Federal .38 special round located inside of it,” police said.