A gunman who killed four people in Northern California rammed a pickup through a locked gate and marched onto the grounds of an elementary school, but he could not enter the classrooms, authorities say.

He fired his rifle through windows and walls, and tried the doors, but the buildings at the Rancho Tehama Reserve school were secure.

Only an outside bathroom was open, but it was empty.

Staff at tiny Rancho Tehama Elementary School west of Corning had moved quickly when they heard gunfire nearby Tuesday morning, assistant Sheriff Phil Johnston said.

They locked the doors after students dashed inside and crawled underneath their desks.

The shooter could not get inside, and left six minutes later, apparently frustrated.

One student was wounded by gunfire and was in stable condition, the school district said. Others were hurt by flying glass.

At least 10 people were wounded or hurt in the string of shootings in Rancho Tehama, about 125 northwest of Sacramento. The shooter was killed by police.

'Killing people at random'

In all, the gunman's rampage involved seven shooting scenes.

His motive remains unclear, but a dispute with a neighbor found dead Tuesday may have sparked the rampage, authorities said.

"This individual shooter was bent on engaging and killing people at random. I have to say this incident, as tragic and as bad as it is, could have been so much worse," Johnston said, applauding the quick thinking of the school staff.

The gunfire that triggered the alert at the school came when the shooter fired from his vehicle into others on his way to the school, about 2 miles from his home.

The killer had a tactical vest with extra magazines, and apparently chose most of his victims at random, sometimes firing at passing motorists, homes and gunning down someone after he purposely crashed into another car.

Wounded victims included a mother driving her children to school when the attacker opened fire. The woman was being treated for life-threatening injuries. A child who was in the vehicle was not seriously wounded, according to Johnston.

Mom raced back to school to warn people

A fearless mother may have also helped warn staff at the school about the danger.

Sara Gonzalez said she had dropped her daughter off at the school when the gunman attempted to shoot her when their vehicles passed. She thinks the gunman's windshield stopped the bullet.

She turned her vehicle around.

"I went to my daughter's school and started honking, making people know what was going on," she said.

Gonzalez said the gunman fired at her as she tried to get out to get her girl. She saw the man's face but he said nothing.

Jessie Sanders told CNN affiliate KCRA he tried to draw the gunman's attention away from the school.

He said he ran over to the school when he heard the crack of the semi-automatic rifle.

"When I get there, the dude was shooting through the windows," he told the Sacramento-based station. "And I said, 'Hey why don't you shoot this way instead.' "

Sanders said a bullet grazed his right forearm.

In the school the children were trying to stay low.

Gonzalez's daughter, Arianna Ibarra, was inside on the floor with her fourth-grade class.

"Our teacher told us to go under our desk and keep flat in case he comes inside," Arianna said.

The teacher blocked the door with a computer, the 10-year-old said.

Known to law enforcement

Johnston said the gunman had "prior contacts with law enforcement." In January the man was arrested on suspicion of assault with a deadly weapon in a case that involved the neighbor who died Tuesday, Johnston said.

Johnston added that the woman had a restraining order against the shooter.

It was unclear whether the gunman went to the school looking for someone he knew.

"We have not connected him with any one person in the school," Johnston said.

A semi-automatic rifle and two handguns believed to be used by the gunman have been recovered, according to Johnston. There is another gun that police have yet to recover in one of the stolen vehicles.