The gunfire erupted around 10:30 a.m. local time on the campus of North Park Elementary School, police said.
"We believe this to be a murder-suicide," San Bernardino Police Chief Jarrod Burguan said. "Happened in a classroom. Two students have been transported to the hospital."
A short time later, police reported the "current threat at North Park ES has been neutralized."
A shaken neighbor told NBC News the first inkling she got that something was amiss was when she "noticed helicopters circling."
"I realized there were two, and I looked outside and the kids were being evacuated up our street," said the woman, who asked not to be identified.
Several of the children appeared to be crying and holding the hands of their teachers, she added.
San Bernardino was the setting for one of the nation's worst mass murders. On Dec. 2, 2015, Syed Rizwan Farook and Tashfeen Malik barged into a county health department Christmas Party and opened fire, killing 14 people.
The radicalized couple was later killed by police.