Rampaging through a small Northern California town, a gunman took aim on Tuesday at people at an elementary school and several other locations, killing at least four and wounding at least 10 before he was fatally shot by the police, the local sheriff’s office said.

There were at least seven separate shooting scenes in or near Rancho Tehama Reserve, an unincorporated community of about 1,500 people, Phil Johnston, assistant sheriff of Tehama County, told reporters. The gunman, later identified as Kevin Janson Neal, 44, entered the elementary school but was unable to get into the classrooms because school officials had heard gunshots outside the building and locked the doors, he said.

At least two of the injured are children, officials said, who were struck after the gunman fired in a school hallway. The dead were all adults.

“This incident, as tragic and as bad as it is, could have been so much worse if it wasn’t for the quick thinking and staff at our elementary school,” Mr. Johnston said.