It happened at Hares Hill Elementary School in Phoenixville, Pennsylvania.
Police say the student discovered the gun and immediately reported it to a school counselor.
The child's father, 58-year-old Russell Matthews, told police he put the gun in the wrong backpack.
He faces numerous charges, including endangering the welfare of a child.