A 17-year-old student shot his ex-girlfriend at a Maryland high school Tuesday morning before he was fatally wounded during a confrontation with a campus security officer, authorities said.

Austin Wyatt Rollins was armed with a Glock semi-automatic handgun when he stormed Great Mills High School around 7:55 a.m., before classes began for the day, St. Mary’s County Sheriff Tim Cameron said at a press conference.

A student resource officer, who responded to the gunfire, and Rollins both fired a single shot at the same time — and it’s not yet clear whether Rollins committed suicide or was killed by the officer’s bullet, Cameron said.

The shooter died at a hospital at around 10:40 a.m.

A 14-year-old boy was shot in the leg but in good condition. It’s unclear who shot him. The female victim was in the intensive care unit with life-threatening injuries.

“There is an indication that a prior relationship existed between the shooter and the female victim,” said Cameron, who declined to comment on the extent of that relationship. “We are working to determine the extent of that and if it was part of the motive.”

The officer, who is also a SWAT team member, was not injured.

Cameron said police are interviewing witnesses and reviewing surveillance video of the shooting. They’re also searching Rollins home.

The sheriff said the incident lasted just “seconds” from when Rollins entered the school to when the officer responded.

“On this day we realize our worst nightmare, that our greatest asset, our children, were attacked in a bastion of safety and security,” Cameron said.

Last month, school officials investigated threats made to Great Mills but deemed them to be “unsubstantiated.”

Cameron said Tuesday’s shooting and those threats, which he called “hoaxes,” are not related.

“No parent should ever have to worry about when they send their kids off in the morning to school whether they’re going to come home safely or not,” said Gov. Larry Hogan. “We need more than prayers. We’ve got to take action.”

Earlier Tuesday, the district, St. Mary’s County Public Schools, tweeted that the situation was “contained” and that the school was under lockdown.

“There has been a Shooting at Great Mills High School. The school is on lockdown the event is contained, the Sheriff’s office is on the scene additional information to follow,” the tweet said.

Just before 10 a.m., the district tweeted that evacuations were taking place.

“Students are being evacuated from GMHS and being bused to the reunification center at the Leonardtown HS campus,” the tweet said. “The building is orderly and the Sheriff’s Office is conducting an investigation. We will continue to update as more information becomes available.” https://twitter.com/smcps_md

Video posted on Facebook shows police running into the school with their weapons drawn.

Other footage shows a massive police response and yellow tape cordoning off the perimeter of the school, which has roughly 1,600 students.

Senior Terrence Rhames heard a shot around 8 a.m. while standing with friends outside their first-period class, according to the Baltimore Sun.

As he was running toward the nearest exit, he saw a girl fall.

“I just thank God I’m safe,” said Rhames, 18. “I just want to know who did it and who got injured.”

The federal Bureau of Alcohol, Tobacco, Firearms and Explosives tweeted that special agents were en route to the school.

Sen. Ben Cardin tweeted, “My thoughts this morning are with the students and families of Great Mills High School (@GMHS_SMCPS ). I will be monitoring the situation as it unfolds. Parents, please follow school and @firstsheriff instructions to be reunited with your children safely.”

Parents of Great Mills students were urged to stay away from the school and instead head to nearby Leonardtown High School to reunite with their children.

The shooting comes a month after 17 people were killed at Marjory Stoneman Douglas High School in Parkland, Florida.

The Parkland massacre has inspired student-led “March for Our Lives” rallies against gun violence and mass shootings that are set for this Saturday, including one in Washington.

Last month, two boys, ages 15 and 16, were arrested for making a “mass threat” to Leonardtown High School — which is about 15 minutes from Great Mills — and bragging that they were “too smart to get caught,” according to WJLA.

Twenty-five guns — including semi-automatic rifles, handguns and ammunition — were seized from both teens’ bedrooms.

Additional reporting by Tamar Lapin