CHARLOTTE, N.C. — In an alert that flashed across computer and phone screens all over campus, the instructions were spare but urgent: “Run, Hide, Fight. Secure yourself immediately.”

But Riley Howell could neither run nor hide. The gunman was in his classroom. So, the authorities said, he charged at the gunman, who had already fired several rounds, and pinned him down until police officers arrived.

“But for his work, the assailant may not have been disarmed,” Chief Kerr Putney of the Charlotte-Mecklenberg Police Department said of Mr. Howell, who was shot in the process and among six victims of a mass shooting at the University of North Carolina at Charlotte campus Tuesday evening. “Unfortunately, he gave his life in the process. But his sacrifice saved lives.”

On Wednesday, students and teachers were still reeling from the attack that left two students, including Mr. Howell, dead and four others injured. Chief Putney said the death toll could have been far worse had Mr. Howell, a 21-year-old former high school soccer goalie, not intervened.