A school resource officer responded shortly before noon to Silverado High School, according to a statement from the San Bernardino County Sheriff's Department.
School staff and security personnel had contacted the student and found the gun, as well as a loaded magazine in a separate pocket of the backpack, investigators said.
The sheriff's deputy interviewed the student, who was then arrested and booked into juvenile hall.
Anyone with information about the incident is asked to call the sheriff's Victor Valley station at (760) 552-6800.