Ryan Heber
Californian teacher Ryan Heber with his wife, fellow Taft Union High School teacher, Emmy Lou Heber (Facebook)

A Californian teacher has been hailed a hero after talking a 16-year-old gunman into giving up his weapon - a shotgun - after he opened fire on classmates.

Ryan Heber was teaching a science class at Taft Union High School outside Bakersfield when a student walked into the room armed with a 12-gauge shotgun.

The gunman, whose name has not been revealed, reportedly confronted one of Heber's pupils by name and then shot him in the upper body. He then named a second student and opened fire in his direction but missed.

"Miraculously, [the second shot] didn't injure anyone," Kern County sheriff Donny Youngblood said.

Heber, who was hit by a shotgun pellet, stepped in and tried to calm down the boy. Campus supervisor Kim Lee Fields joined in and together they convinced the gunman to put down his weapon before police arrived.

The other 27 students in the classroom escaped through the back door.

"The heroics of these two people goes without saying," Youngblood said. "They stood there face-to-face [with the gunman] not knowing whether he was going to turn that shotgun on them."

"His students like him a whole bunch. He's not the kind of teacher a student would try to hurt," Heber's father David, 70, told the Bakersfield Californian. "He's definitely someone who could talk a kid down in an emergency."

According to the scenario reconstructed by Youngblood, the armed student said to Heber: "I don't want to shoot you."

The boy had been suspended from the school in 2012 after threatening to kill schoolmates who had been bullying him but had eventually been allowed to return to class.

"He was telling everyone that he had a list of people who messed with him over the years and that he was going to kill them," Angela Hayden, whose daughter attends Taft school, told the LA Times.

"He believed that the two people he targeted had bullied him. Whether that occurred or not we don't know yet," Youngblood said.

The shot student was flown to hospital in Bakersfield, where he was in critical but stable conditions.

Two girls suffered from minor injuries in the panic to escape.

The shooting happened on the day that US vice-president said he would be ready to send gun control proposals to President Barack Obama and just weeks after lone gunman Adam Lanza killed 20 young children and six adults at Sandy Hook Elementary School in Connecticut.

The killings reinvigorated discussions over America's relaxed gun control laws.