The rookie teacher, who started in January, quickly wheeled a grand piano in front of the door and ushered dozens of her students into an office, locking the door behind them.

The students sat on Ms. Holt’s floor with the lights off. They were afraid, they were crying, but they also knew how to keep safe, she said. They knew to muffle their sobbing. They knew to keep their phones silent and dark. One quietly called the police. Another grabbed a fire extinguisher — just in case the gunman made it inside.

Ms. Holt also knew what to do. After barricading the door, she grabbed a gunshot wound kit that she keeps in her classroom and wrapped the wounds of the freshman girl who had been shot in the torso and shoulder, she said. The girl survived.

Students and teachers had gone through a lockdown drill in the spring, Ms. Holt said. But even after the gunshot wound training, the lockdown drill, the school shootings on the news, Ms. Holt still held out hope that she and her students would not face one themselves.

“I really, truly did not believe that this was going to happen to me, which was really ignorant,” Ms. Holt said. “Every time this happens, in every interview, they always say that, and I still really thought it wasn’t going to happen.”

California has some of the toughest gun laws in the nation and has long restricted the maximum capacity of detachable magazines for semiautomatic firearms — such as the one the police described the gunman as using — to 10 rounds. It is also illegal for minors in most cases to possess handguns in the state.