An armed school resource officer intervened and engaged a gunman who had opened fire at a Maryland school Tuesday morning.

“When the shooting took place, our school resource officer, who was stationed inside the school, was alerted to the event and [to] the shots being fired,” St. Mary’s County Sheriff Tim Cameron said of the shooting at Great Mills High School.

“He pursued the shooter, engaged the shooter, during which that engagement he fired a round at the shooter,” Cameron said.

The shooter, Austin Wyatt Rollins, 17, who used a handgun and is now dead, shot two students, one male and one female.

An investigation will ascertain whether the fire from the armed school resource officer, Deputy First Class Blaine Gaskill, killed Rollins, The Daily Caller reported, or whether Rollins shot himself.

One of the victims, a 16-year-old female student, was in critical condition, and the 14-year-old male victim was in stable condition, CNN reported.

Gaskill, 34, is a SWAT-trained officer of the St. Mary’s County Sheriff’s Office, The Washington Post reported.

Since the Feb. 14 shooting in Parkland, Florida, that left 17 people dead, President Donald Trump has called for arming up to 20 percent of staff at schools to put protections in place for students and to prevent future mass shootings.

“This is what we train for, this is what we prepare for, and this is what we pray that we never have to do,” Cameron said. “On this day, we realized our worst nightmare.”

Amy Swearer, a visiting legal fellow at the Meese Center for Legal and Judicial Studies at The Heritage Foundation, told The Daily Signal in an email that the outcome of the shooting could have been worse without the armed officer.

“It is extremely fortunate that this armed school resource officer took immediate action to confront—and ultimately end—a serious threat of violence directed against the students of Great Mills High School,” Swearer said.

“This is a deeply troubling incident that could have been much worse if not for the officer’s quick and decisive response,” she said. “It underscores the need to ensure the nation’s students are adequately safeguarded against violent attacks.”