SAN BERNARDINO, Calif. -- A man walked into his estranged wife's elementary school classroom in San Bernardino and opened fire without saying a word, killing her and an 8-year-old student before shooting himself in a murder-suicide that spread panic across a city still recovering emotionally from a terror attack just 15 months ago.

A 9-year-old student also was critically wounded. He and the boy who died were behind their special-education teacher, Karen Elaine Smith, 53, the target of the man she had married months earlier, police said.

The shooting left hundreds of distraught parents waiting for hours to reunite with their children.

Staffers knew Cedric Anderson, who had been estranged from his wife for about a month, and he got into the school by saying he had to drop something off for Smith, officials said.

"No one has come forward to say they saw this coming," police Chief Jarrod Burguan told reporters.

Anderson had a history of weapons, domestic violence and possible drug charges that predated the short marriage, authorities said.

He frequently wrote social media posts about his wife over the past month. On what appeared to be his Facebook page, Anderson said he "loved being married to Karen Smith-Anderson!" and posted a photo of the two of them on March 4 in what he described as a date night. He posted several photos of his wedding to Smith early this year and their honeymoon in Sedona, Arizona.

Smith's mother, Irma Sykes, said her daughter had been friends with Anderson for about four years before they got married.

"She thought she had a wonderful husband, but she found out he was not wonderful at all," Sykes told the Los Angeles Times. "He had other motives," Sykes said. "She left him and that's where the trouble began. She broke up with him and he came out with a different personality. She decided she needed to leave him." She did not elaborate further.

Sykes said her daughter was a dedicated teacher who took up the profession about 10 years ago after her four children grew up.

Fifteen students ranging from first to fourth grade were in the special-education classroom at North Park Elementary School, along with two adult aides and Smith, when Anderson emptied a large-calibre revolver and reloaded. Then, he turned the gun on himself.

Marissa Perez, age 9, was in the classroom hiding under a table.

"A boy just walked in with a gun," she said shortly after she and her mother, Elizabeth Barajas, were reunited. The two cried, hugged and trembled. Barajas held the sweater her daughter had been wearing. It was speckled with blood.

"He just shot everywhere," Marissa said. "My friend and my teacher. They got shot."

Jonathan Martinez, the 8-year-old, was airlifted to a hospital and died soon after arriving, Burguan said. The 9-year-old boy, whose name was not released, has been stabilized at a hospital.

The 600 other students at the school were bused to safety at California State University's San Bernardino campus, several miles away, after many walked off campus hand-in-hand, escorted by police.

Panicked parents had to wait hours before being reunited with them at a nearby high school.

Holly Penalber, whose 9-year-old son and 7-year-old daughter attend the school, called it "every parent's worst nightmare." She said the long wait was "frustrating but also understandable."

When the buses first pulled away from the elementary school, some parents ran 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.

When students got to the high school, many carrying glow sticks they had been given to pass the time, they got hugs from emotional parents, many in tears. Police officers applauded and high-fived them.

Alberta Terrell said she cried with relief when she was told that a family friend saw her 9-year-old granddaughter getting safely onto a bus.

"I was really elated. But I won't be truly happy until I see her and can give her a big hug," Terrell said as she sat in the bleachers near Cajon High School's baseball diamond, waiting for her granddaughter to arrive.

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.

"Tragedy has again befallen our city," Police Lt. Mike Madden said Monday of a community that has struggled in recent years.

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. It was hit hard by the great recession, seeing rises in unemployment and violent crime.

An overflow crowd gathered at sunset at Our Lady of the Assumption Church in San Bernardino to mourn and pray for the victims and survivors of Monday's shooting.

"Sometimes all we can do is cry. And today is the day for that," Bishop Gerald R. Barnes told the gathering. "We'll get up again. We'll move on. We'll become stronger. But today is the day to cry."

------

Associated Press writers Michael Balsamo, Brian Melley, John Rogers, John Antczak, Amanda Lee Myers and Andrew Dalton contributed to this story.