HAMILTON, Ohio — A 14-year-old boy pulled out a gun in a school cafeteria Monday and opened fire, hitting two students, and then ran from the school, threw the weapon down and was apprehended nearby with the help of a police dog, authorities said.

Two other Madison Local Schools students also were injured, possibly from shrapnel or from running away. None of the injuries appeared to be life-threatening, said Butler County Sheriff Richard Jones.

Jones said the 14-year-old was a student and there was a motive to the shooting which he did not identify.

The boy was charged preliminarily with two counts of attempted murder, two counts of felonious assault, inducing panic and making terrorist threats, Jones said.

Students were eating in the cafeteria when the shooting happened around 11:30 a.m., Jones said. Afterward, classmates described a chaotic scene where they weren’t sure what was happening at first.

Thirteen-year-old Shelby Kinnin said she heard “a couple of bangs” and realized she was near the gunman.

“I didn’t really know it was gunshots until I looked over and a kid was grabbing his leg and falling over,” she said.

Many people ran from the scene, and the shooter went out a door, she said. She recognized him as a boy who was in a class with her last year, though she wasn’t sure of his name.

Her stepmother, Stephanie Kinnin, said it was unnerving to see emergency responders swarm the school.

“There is no feeling like that in the world,” she said. “But my eyes found the children walking out looking for parents, and that was heartbreaking. Their eyes just told the story.”

The students who were shot were 14 and 15 years old and were taken to a hospital where they were in stable condition, investigators said. A 14-year-old boy and 14-year-old girl were also injured, though it was unclear how, Jones said.

“We don’t know if it was from the shooting or from exiting the school or because of the shrapnel from the bullets hitting into that small of an area,” Jones said.

Students who were in the cafeteria at the time said they didn’t immediately recognize the sounds as gunshots. Some students ran outside to a field before being brought back inside.

A sheriff’s deputy stationed in the school had just been in the cafeteria, Jones said.

All other students were safe, according to the school website. The school, which had practiced for such an event, immediately went into lockdown, said district spokeswoman A.J. Huff.

The campus is near Middletown, roughly 30 miles north of Cincinnati. State records show enrollment of about 250 junior high and 500 high school students.