Police said late Thursday afternoon that Rashaad L. Byrd, 27, of Romeoville brought the 9 mm handgun with him while he was staying in an apartment in Elgin with the boy and his relatives.
The boy had found the weapon and brought it to school Thursday morning. Police said the boy was too young to be charged.
Byrd has been charged with possession of a weapon by a felon, not having an FOID card and misdemeanor child endangerment, police said. He was taken into custody and is scheduled to appear in bond court Friday morning.
Elgin police were called just after 10 a.m. to Gifford Elementary School at 240 S. Clifton Ave. after a staff member called to report a second-grader had brought a gun into the building.
After staff confiscated the backpack, a search found a loaded 9mm pistol inside, police said.
A statement from Patrick Mogge, director of School & Community Relations for School District U46 in Elgin, said the gun was first spotted by another student, who notified staff.
"Staff took immediate action and secured the backpack in the main office and called the police," the statement said. "The Elgin Police Department identified it as a loaded handgun."
The 7-year-old boy was taken to the school office to speak with staff and officers, the statement said.
Police had set up a perimeter around the school and used a K-9 unit to search the building and all lockers for additional weapons, but none were found. Class returned to normal 90 minutes later.
"We have not identified threats or intention to harm anyone," Mogge said in the statement. "No injuries occurred. The staff did a great job of taking immediate action."
School security officials are still trying to determine why the boy brought the gun to school, and whether he knew it was real.
"We're not sure why he brought the gun to school, but we don't have any information that suggests there were any threats of any kind made at the school at this time," said John Heiderscheidt, District U-46 Security Chief.
The Elgin police chief confirms he has heard reports that the boy's mother may have called the school to complain about bullying. The police say that they and the school district are following up on those reports.
The Sun-Times Media Wire contributed to this report.