A SWAT team entered the room at Castle View Elementary School, east of Los Angeles, shortly before 6 p.m., Officer Ryan Railsback said.
Negotiators had been talking to the man but hadn't heard from the woman.
"We, of course, had been fearing for the hostage's life all day," Railsback said, but the decision to hurl distracting flash-bang grenades and storm the classroom was made because "the fear for her safety was increasing."
The children were at lunch and were not in the classroom when the man barricaded himself inside with the teacher, said Justin Grayson, a spokesman for the Riverside Unified School District.
The man was seen being wheeled away on a gurney into an ambulance. There was no immediate word on his condition. The teacher was sent to a hospital for examination but didn't appear to be injured, Railsback said.
Family members and the school identified her as first-grade instructor Linda Montgomery, who had taught at the school for about 20 years.
"She's really good with kids," granddaughter Ariana Montgomery told KABC-TV. "She's really helpful and sweet."
It's still not clear what prompted the man to enter the school shortly before 11:15 a.m. and barricade himself with the teacher, and it wasn't immediately known whether he had a weapon although he did bring a backpack onto campus, Railsback said.
The suspect had suffered an "emotional breakdown" that morning, his uncle Carl Jackson told the station.
"He's not dangerous," Jackson said before the standoff ended. "It's just a matter of getting in there and talking to him, because we can talk to him."
VIDEO: Riverside barricade suspect's family speak out
The man had barged into the school office, where he failed to sign in, and was later seen grabbing the teacher.
The husband of another teacher was on campus and tried to intervene but the man punched him in the face, knocking him down and breaking his nose, Railsback said.
Students initially were kept inside their classrooms before being ordered to evacuate to a local park, walking down the street in a long line.
Madison Barber-Alvarez told KABC-TV that she and her classmates were held in the room for two hours.
"I felt like that this is so terrifying. I thought this going to be my worst nightmare I've ever had," the 12-year-old said.
VIDEO: Riverside mom, daughter reunited amid hostage situation
"We were praying that we're going to be OK," she said.
All were safely accounted for but school was canceled for the rest of the week, according to the school district.