It happened Wednesday in Vernon Johns Middle Academy in the 6300-block of South Hermitage on Chicago's South Side.
School officials say the boy told sixth grade classmates he had a gun. Students alerted the teacher who called an off-duty Chicago Police officer working as a security guard. The gun discharged as the officer searched the boy's desk.
Thirteen students were in the classroom at the time.
The boy could be expelled.