Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A parent barricaded an elementary school classroom and held a teacher hostage in Southern California for six hours before a SWAT team stormed the room, officials said Tuesday.

The man was injured in an officer-involved shooting and was being treated at a hospital, Riverside police Officer Ryan Railsback said Tuesday night. The teacher, identified by the Riverside Unified School District as Linda Montgomery, wasn't injured in the incident at Castle View Elementary School in Riverside, about 50 miles east of Los Angeles.

It may have begun when a parent tried to take his or her child from the school and was refused, said a law enforcement official familiar with the investigation, who stressed that the information was preliminary and that police were still trying to piece together a possible motive.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Police negotiators worked to de-escalate the situation for hours, but the decision to enter the classroom finally had to be made, Railsback said.

"We've been in fear of the victims' safety the entire day," he said, adding that Montgomery, too, was taken to a hospital as a precaution.

"I can't imagine what she's gone through," Railsback said. "She’s going to suffer some emotional trauma, but we're glad she is alive and she is safe now."

No students were in the classroom at the time, and children at the school were evacuated to a nearby park, said Justin Grayson, a spokesman for the Riverside Unified School District. The school said all students had been accounted for.

A parent was holding a teacher hostage in a classroom at Castle View Elementary School in Riverside, California and students were being evacuated while the school was locked down, on Oct. 31. NBC News

School officials said classes would be canceled for the rest of the week. Counselors and support staff will be made at a nearby school for anyone who needs extra emotional support, said Justin Grayson, a spokesman for the Riverside Unified School District.

Superintendent David Hansen said the harrowing incident would trigger a re-evaluation of how to keep the school safer in the future.

"As unfortunate as this incident is, it is something that we will learn from, and we will continue to review and enhance our security measures," he said.