SAN BERNARDINO, Calif. — A husband opened fire on his wife Monday in a San Bernardino elementary school classroom, killing her and a student in a murder-suicide that spread panic across a city still recovering emotionally from a terrorist attack at a community center just 15 months ago.

The gunman also died, and a second student was critically wounded at North Park School.

“The children we do not believe were targeted,” police Capt. Ron Maass told reporters.

The gunman was identified as 53-year-old Cedric Anderson of Riverside, who shot his wife, Elaine Smith, also 53. She was a teacher in the special-needs classroom for students in first through fourth grades.

Anderson said nothing as he began firing a large-caliber revolver, according to police. Both of the children who were hit were standing behind Smith. An 8-year-old later died. The other student was hospitalized in stable condition.

The gunman had a history of weapons, domestic violence and possible drug charges that predated the marriage, which lasted only a few months, authorities said.

The boy who died was identified as Jonathan Martinez. Authorities did not name the other boy who was wounded.

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, some in tears, some praying as they anxiously sought information about their children. They were told to go to a nearby high school, where they would be reunited.

Four hours later, the children began to arrive at the high school, getting hugs from emotional parents. As the students got off the buses, many of them carrying glow sticks they had been given to pass the time with, police officers applauded and high-fived them.

When the buses first pulled away, some parents ran alongside, waving and trying to recognize their children inside. Many said their children were too young to have cellphones.