A teacher has been shot dead and two pupils have been critically injured in an apparent murder-suicide at a California primary school.

The suspected gunman who opened fire in a classroom at North Park School in San Bernardino also died.

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 hospital where they were listed in critical condition.

"The children we do not believe were targeted. The suspect had come to the classroom to visit," police Captain Ron Maass said.

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, parents raced to the school as they sought information about their children. They were told to go to a nearby high school where they would be reunited with their children.

Jeanette Gordon, who lives near the primary school, said she sensed something bad had happened as soon as she heard sirens.

As she waited to be reunited with her 11-year-old daughter, she passed the time pacing nervously and texting on her phone.

"I can't wait to see her. I can't wait to see a lot of the kids, all of them," Ms Gordon, 41, said. "I'm just trying to stay calm. It's for my daughter. I have to stay calm and pray."

She said she knew her daughter was safe because she had heard from others that authorities had already contacted parents of the wounded children.

A few minutes after buses began leaving the primary school, they began arriving at the university. Officials said they could be there for several hours as police interview them.

"It's frustrating for us as parents but also understandable," Holly Penalber said of the long wait.

Ms Penalber's nine-year-old son and seven-year-old daughter attend the school. She called Monday's shootings "every parent's worst nightmare".

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 battle with authorities.

Monday's shooting was the latest tragedy for a city that has struggled in recent years with more than its share. 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.