Police stopped a Boston teenager who attempted to bring a loaded handgun to school on Thursday.

The suspect, a 15-year-old student at TechBoston Academy, was carrying a .32 caliber handgun in his backpack, police said.

The school's dean of discipline John Evans told police the teen arrived late to school and tried to bypass the metal detectors at the school's entrance, according to a police report.

When officers spotted the gun in the boy's unzipped backpack, the teen fled, then resisted arrest, police said. 

The teen, who is from Dorchester, was arrested and charged with unlawful possession of a firearm and ammunition and resisting arrest. 

"There is never a good reason to bring a gun to school. Illegal guns have no place on our streets and certainly not in the hands of a child," said Boston Police Commissioner William Evans in a statement. "Thanks to the keen observations and quick actions of the school police officers and administrators, a potential tragedy was avoided and one less gun is on the streets."