BALTIMORE, Maryland - A student who opened fire at a Maryland high school died Tuesday morning, the police said. The campus was on lockdown as deputies and federal agents converged on the crime scene at Great Mills High School.

St. Mary's County Sheriff Tim Cameron said a student shot two other students in a hallway before classes began Tuesday morning.

school resource officer then faced off with the shooter, the sheriff said. Each fired one shot simultaneously. Cameron said the gunman later died from his wounds.

He said that the investigation would determine whether the round the officer fired hit the shooter. 

Cameron said it's possible the gunman died of a self-inflicted gunshot wound, but investigators will review surveillance video and determine what happened.

The St. Mary's County Public Schools said the situation was "contained" after the shooting at the school, which has about 1,600 students and is near the Patuxent River Naval Air Station, about 65 miles southeast of Washington.  

A 14-year-old boy was wounded and is in stable condition. A 16-year-old girl who was also wounded is in intensive care with life-threatening injuries, Cameron said.  

There is an indication a "prior relationship" existed between the female victim and the shooter, Cameron said. Investigators are working to determine whether that was part of the motive.  

"This is something that we train, practice, and in reality we hope would never come to fruition, it is our worst nightmare," Cameron said at a press conference Tuesday.

Student Mollie Davis told CBS News over Twitter that she heard what sounded like a loud balloon pop.

"I was in my classroom and heard everyone screaming," Mollie said. "I've never heard people sound so scared."

Police officers told students that the threat was over and the school would be evacuated soon, the student said.

The Baltimore Sun reported that a student said the shooting happened around 8 a.m. Terrence Rhames, 18, told the Sun that he heard a gunshot and saw a girl fall as he ran for an exit. "I just thank God I'm safe," Rhames said. "I just want to know who did it and who got injured."

The county sheriff said deputies were on the scene and told parents or guardians to stay away, urging them to go instead to Leonardtown High School to reunite with Great Mills students there. 

Maryland Gov. Larry Hogan and Rep. Steny Hoyer tweeted that they were monitoring reports and urged people to follow the instructions of local law enforcement at the scene.

The school is in the congressional district of Rep. Steny Hoyer, who tweeted that he's closely monitoring reports and urged people to follow the instructions of local law enforcement at the scene.

St. Mary's County is located south of Baltimore.

The Associated Press contributed to this report.