First-year social studies teacher Megan Silberberger intervened in the attack Friday at Marysville-Pilchuck High School, teachers union president Randy Davis said.
The teacher intercepted the gunman as he paused, possibly to reload, student Erick Cervantes told KIRO-TV.
"I'm completely amazed by her actions and I feel for her," Davis told The Associated Press. "I don't know why she was in the cafeteria but I'm just grateful she was there."
However, it wasn't clear if the shooter committed suicide or if he accidentally shot himself in the struggle with the teacher.
More From This Section
A school resource officer also ran to the scene, Davis said.
The shooter was Jaylen Fryberg, a popular freshman at the school, a government official with direct knowledge of the shooting told The Associated Press. The official spoke on condition of anonymity because he was not authorized to speak to the media.
Fryberg left months of troubling messages on social media, and friends said he'd recently been in a fight over a girl. One of his tweets said, "It breaks me ... It actually does ..."
The tight-knit Native American community on scenic Puget Sound struggled to cope with the tragedy.