SAN BERNARDINO, Calif. — For Elizabeth Barajas it had been an hours-long nightmare waiting to learn the fate of the daughter she had dropped off at school a couple of hours before police reported that gunfire in a classroom had killed two adults and wounded two children.

Then, in some ways, the nightmare became worse.

Barajas learned her daughter, Marissa Perez, had been sitting at her desk Monday morning when a gunman stormed into her classroom, shot her teacher to death, killed one of her classmates and wounded another before killing himself.

“I don’t know what to do. I don’t know what to tell her,” Barajas said as the two held each other and sobbed after the ordeal that sent police flooding onto the campus of San Bernardino’s North Park School.

As Marissa and about 600 other students were shepherded to safety, Barajas and hundreds of other parents raced to the school. There they would endure an agonizing four-hour wait before learning that all but two of their children were physically if not emotionally unharmed.

“She just said she was scared. As soon as she saw the guy with the gun, she went under the table. She keeps telling me ‘My teacher got shot, my friend got shot,’ ” Barajas said as she clutched her daughter’s blood-stained sweatshirt.

Marissa said the shooter didn’t say a word as he opened fire. One of her friends was hit, she added, as she pointed to her abdomen.

Police identified the gunman as Cedric Anderson, 53, of Riverside. They believe he arrived at the school intending to kill his estranged wife, North Park teacher Elaine Smith, and accidentally shot the two children.

Many of the parents of the school’s 600 students were at home when the blaring sounds of emergency vehicle sirens shattered the morning quiet of their neighborhood.

Amberly Raffle, who had left her son with his pre-kindergarten class earlier that morning, said she wasn’t sure what the sirens were about until her sister-in-law ran to her house to tell her there was a problem at the school.

“Policemen were everywhere and ambulances, firetrucks, helicopters,” she said of the scene she saw. “I got really scared then.”

It was “every parent’s worst nightmare,” said Holly Penalber as she wiped tears from her face while waiting to hear the fate of her 9-year-old son and 7-year-old daughter.

Penalber, a Riverside County sheriff’s deputy, was on a training assignment when she began getting frantic texts from her husband and mother, saying something bad had happened at the school.

Then she waited hours outside a nearby high school where parents were eventually reunited with their children. She was too nervous to join Barajas and others in the library, saying there were more rumors than information there. But eventually she heard from someone who had seen her children and assured her they were safe.

“It was such a sigh of relief. But I won’t feel good until I hold my kids,” she said.

One of the first parents to be reunited with a child was Raffle, who cried tears of joys as she embraced her son.

“He doesn’t really know what happened,” she said. “I think we’re blessed because of that.”

Barajas is concerned about what witnessing the shooting will do to her daughter.

“They can’t just tell us your kids are fine,” she said. “Obviously my kid is not fine. She witnessed what happened to her teacher and the other students, and all they said is your kids are safe, your kids are fine.”