While Dwayne Ferguson of Buffalo was charged with two counts of criminal possession of a weapon, authorities said they didn't believe he had any ill intent, WIVB-TV, Buffalo, reported.
The 4:15 p.m. EST incident prompted a lockdown that drew a heavy police response to Harvey Austin Elementary School, a public school serving students from kindergarten to eighth grade on Buffalo's East Side, the Tonawanda News reported. There were about 60 children in the building at the time, WIVB-TV said.
Erie County Executive Mark Poloncarz said a caller to the emergency dispatch center reported seeing a man with a gun inside or on the campus.
An initial search by law enforcement officers failed to turn up a weapon but the teacher allegedly was found with the gun during a second round of searching, the newspaper said.
City police department spokesman George DeGeorge said while Ferguson has a permit for the gun, it is a felony for non-law enforcement personnel to carry firearms on school grounds in New York state.
Authorities said Ferguson is not a Buffalo school system employee but is a regular participant in after-school programming at the school.
Rosie O'Donnell unveils nearly 50-pound weight loss
Putin thinks Obama would save him if he were drowning