Two students were injured and a gunman was killed at Great Mills High School in Southern Maryland on March 20. (Patrick Martin,Zoeann Murphy/The Washington Post)

Deputy Blaine Gaskill rushed toward the sound of gunshots in a Maryland high school Tuesday, putting himself not only in the line of fire but also at the center of the white-hot national debate on school safety.

Gaskill, a 34-year-old SWAT-trained officer of the St. Mary’s County Sheriff’s Office, was working as the school’s resource officer when a student opened fire in a first-floor hallway, striking a female student and possibly a male classmate. Gaskill confronted the shooter as students and teachers scrambled for cover. Both fired their weapons, and the gunman was fatally wounded. Gaskill was not injured.

Investigators were still reviewing video and taking testimony to determine exactly what happened in the chaotic exchange that sent two students — a girl, 16, and a boy, 14 — to the hospital with injuries. Officials could not say who shot the boy or whether the attacker, 17-year-old Austin Wyatt Rollins, was killed by Gaskill or shot himself with the Glock semiautomatic handgun he brought to the school.

In any case, Gaskill’s rapid response was hailed for short-circuiting the attack before it became another school massacre. St. Mary’s County Sheriff Timothy K. Cameron said there was “no question” that the officer’s quick arrival at the scene and immediate engagement with the shooter had prevented more injuries. Maryland Gov. Larry Hogan (R) praised Gaskill as “a tough guy” and promised to push for a $125 million package that includes more funding for school resource officers.

Blaine Gaskill, the St. Mary’s County sheriff’s deputy assigned to Great Mills High School, was the school resource officer who engaged the shooter. (Julie Yingling/St. Mary’s County Sheriff’s Office)

Proponents of increased school security immediately embraced Gaskill as a real-world example of what a well-trained “good guy with a gun” can do when a school is under fire. Many contrasted Gaskill’s actions with those of the uniformed resource officer shown on videotape waiting outside Florida’s Marjory Stoneman Douglas High School during a February shooting that left 17 people dead.

“We should be having a school walkout to commemorate all the kids that got to walk out of school today thanks to Deputy Blaine Gaskill and his gun,” wrote Twitter user Emily Horst Weaver, whose picture shows her firing a gun. Earlier in the month, she had written, “Nothing disgusts me more than a coward.”

The Twitter feed of NRATV, an arm of the National Rifle Association, hailed Gaskill as proof of the group’s assertion that armed guards — or teachers — are a better response to school shootings than gun control.

“Schools must be the most hardened targets in this country,” said one of the tweets, quoting NRA chief executive Wayne LaPierre. “Today that call from the #NRA was once again proven right.”

Gaskill, a six-year veteran of the department, has been assigned to the school of 1,600 since August. If the investigation shows that Gaskill’s shot stopped the shooter, the deputy would be only the second resource officer to gun down an active school shooter since the Columbine High School massacre in 1999, according to a year-long Washington Post analysis of dozens of school shootings.

As of the 2016 school year, there are more than 300 officers assigned to Maryland schools, according to the Maryland Association of School Resource Officers. Each jurisdiction throughout the state trains officers, with some coming from local police departments and others from county sheriff’s offices.

The number of school resource officers across the nation remains unknown, with no central agency tracking that data. The National Association of School Resource Officers has about 4,500 members, but the organization estimates that there could be anywhere from 14,000 to 20,000 school resource officers across the country.

The group estimates that only 20 percent of the nation’s schools have a school resource officer, which the association defines as “a properly selected, specially trained sworn police officer.”

The organization’s director of operations, Mac Hardy, said SWAT or other high-level training like what Gaskill reportedly received is not unusual among school-based officers. Hardy himself was a SWAT team member for 15 years and worked in schools for 20 years.

He spoke of the difficulty of putting on a gun belt every day, knowing he might have to use his weapon. The national association has spoken against arming teachers, listing among several reasons that without extensive training a person “will likely be mentally unprepared to take a life, especially the life of a student assailant.”

“Luckily the right person was there,” Hardy said of Gaskill. “He had the right training to do what was necessary. Who’s to say, how many lives did he save today?”

One Great Mills student, Isiah Tichenor, recounted Gaskill’s efforts to talk Rollins down, yelling at him: “Put the gun down! We know you don’t want to hurt anyone.”

Gaskill had successfully defused encounters with armed suspects before. In July 2016, he responded to a call not far from the high school during which a man confronted him on the porch of a house with a pistol in his hand. In footage recorded by Gaskill’s body camera, he is heard shouting at the man to put the gun down. The man refuses at first but eventually complies and is arrested with no shots fired. The man was found guilty in February of first-degree assault and use of a firearm in the commission of a violent crime, according to reports.

A Facebook page for the officer’s wife, Amber Gaskill, features a series of inspirational messages. One, displayed against a backdrop of the American flag, reads: “I’m a wife standing with the Thin Blue Line.”

In February, she posted a picture of slain Prince George’s Cpl. Mujahid Ramzziddin and wrote: “This makes me so, so sad....and hits so close to home. My heart breaks for his family.”

Ramzziddin was fatally shot when he was off duty and helping a neighbor who had asked for his assistance in a domestic dispute, police have said.

John Woodrow Cox, Steven Rich, Julie Tate, Jennifer Jenkins and Ann E. Marimow contributed to this report.