A 15-year-old student was arrested after bringing a loaded gun to his Brooklyn school on Thursday morning, the first day of school, police said.

The 22-caliber gun was detected by scanners at the Brooklyn School for Career Development on Clermont Avenue in Fort Greene around 8:50 a.m., cops said. The gun was in the student’s backpack, they said.

Charges were pending against the student, who had not been identified.

Mayor Bill de Blasio on Thursday said the student will face serious consequences, but cautioned that it’s a “very small minority of young people who do the wrong thing.”

“First of all, it’s wrong in every way, and if someone is giving you a weapon, it’s going to take you down the wrong road, if someone tells you to hold a weapon for them, it’s going to take you down the wrong road,” de Blasio said.

“There’s just no place for a weapon in school. On top of that, you’re going to get caught, and it’s going to have very serious ramifications for your life.”