Authorities said one of those killed was a teacher and the other was the suspected shooter who opened fired in a classroom at North Park School.
A school official said the attack was believed to stem from a “domestic dispute” and that the teacher knew the gunman.
The two wounded students were flown to a hospital where they were listed in critical condition, school district spokeswoman Maria Garcia told television station KNBC.
“The children we do not believe were targeted. The suspect had come to the classroom to visit,” police Capt. Ron Maass told a news conference.
The 600 other students at the school were bused to safety at California State University’s San Bernardino campus, several miles away. Television news footage showed students, escorted by police officers, walking off campus hand-in-hand.
As word of the shooting spread, panicked parents raced to the school. They were told to go to a nearby high school where they would be reunited with their children.
As the buses pulled away, some parents raced frantically alongside, waving and trying to recognize their children inside. Many said their children were too young to have cellphones. Others said the phones rang unanswered.
“I just wish I could talk to them to make sure they’re OK because they don’t know what this is all about,” one parent said as she passed reporters.
Marina Ramos told KABC that she rushed to the school to try to pick up her grandson. She said she spoke to him, and he was safe.
“He was crying. He’s scared,” she said. “It was a typical morning and then chaos broke out.”
A few minutes after buses began leaving the elementary school, they began arriving at the university, where students were seen bounding out of their doors.
San Bernardino, a city of 216,000 people about 60 miles east of Los Angeles, was the site of a 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 later killed in a gunbattle with authorities.
Monday’s shooting was the latest tragedy for a city that has struggled in recent years with more than its share of them. Once a major rail hub and citrus producer, San Bernardino filed for bankruptcy in 2012 after struggling to pay its employees despite steep cuts to the budget.
An outlying suburb of Los Angeles, it was hit hard when the Great Recession sent housing prices tumbling. As the city struggled with economic problems that forced layoffs of police and other government workers, violent crimes, particularly homicide, began to rise.
In the past year, however, the city seemed to be making a recovery. Police Chief Jarrod Burguan, who won national praise for the way his department responded to the 2015 shootings, announced last year he was hiring additional officers.
Associated Press writers Michael Balsamo, Brian Melley and John Rogers contributed to this story.