The boy has been booked into juvenile hall on felony charges of carrying a loaded firearm, having a gun on a school campus, and being a minor in possession of a gun and ammunition.
According to the Fresno County Sheriff's Office, an administrator at Clay Elementary School discovered the gun in the boy's backpack Thursday and called authorities.
Deputies arrived to find it was a 25-caliber pistol loaded with six bullets.
The sheriff's office says school officials told deputies the boy had mentioned to other students he had a gun in his backpack and had intentions of shooting a teacher.
The boy was upset with the teacher for punishing him the day before after he was caught punching another student, according to the sheriff's office.
Deputies do not yet know how the boy got the gun. They are investigating the incident.
If you have any more information about the case, you are urged to contact Lt. Brandon Pursell at (559) 600-8029 or Crime Stoppers at (559) 498-7867.