Investigators believe "the suspect is down" and that North Park School faces no further threat, Police Chief Jarrod Burguan said on Twitter.
Two students were airlifted to a hospital after what was believed to be a domestic dispute, San Bernardino City Unified School District spokeswoman Maria Garcia told news station KNBC-TV. Their conditions were not immediately known, police said.
"We believe the teacher knew who the shooter was," Garcia said, adding that all other students were safe.
Students gathered on a field and a blacktop basketball court inside the fenced-in grounds of the campus near a line of school buses. The school has about 600 students in kindergarten through sixth grades.
Frantic parents running up a sidewalk looking for information about their children were not able to learn immediately what happened. Several parents interviewed on TV said their children were too young to carry mobile phones, so they had not been able to contact them to see if they were safe.
Marina Ramos told news station KABC-TV that she rushed to the school to try to pick up her grandson after she heard about the shooting. She said she spoke to him, and he told her he was safe but was upset.
"He was crying. He's scared," she said. "It was a typical morning and then chaos broke out."
Students were being taken to local college campus, Garcia said.
The city of 216,000 was the site of the December 2015 terror attack that killed 14 people and wounded 22 others at a meeting of San Bernardino County employees. Husband-and-wife shooters Syed Rizwan Farook and Tashfeen Malik were killed in a gunbattle with authorities later that day.
The city is known for its high rates of violent crime, especially homicides, and has struggled to emerge from bankruptcy.
SAN BERNARDINO, Calif. (AP) — An apparent murder-suicide inside an elementary school classroom in San Bernardino left two adults dead, including a teacher, and two students wounded, police and school officials said.