A male student at a high school in Maryland shot a 16-year-old girl he knew with a handgun on Tuesday, spurring a confrontation with an armed deputy stationed at the school, the authorities said.

When the chaos was over, perhaps a minute after it began, the girl was critically injured, a 14-year-old boy was hurt and the gunman, whom the authorities identified as Austin Wyatt Rollins, 17, was fatally wounded.

Great Mills High School, near a weather-beaten water tower in southern Maryland, became the latest scene of a school shooting, a little over a month after a teenager killed 14 students and three adults at Marjory Stoneman Douglas High School in Parkland, Fla.

“If you don’t think this can happen at your school,” said J. Scott Smith, the superintendent for St. Mary’s County, which includes Great Mills High, “you are sadly mistaken.”

The shooting here comes amid renewed urgency in the nation’s debate over gun control, with demonstrators around the country planning a nationwide march this weekend.

It is likely to draw further attention to the role of armed personnel in schools, which has been widely discussed after surveillance video showed that a sheriff’s deputy posted at the school in Parkland did not go inside a building to engage the gunman during that shooting, an apparent violation of protocol.

The authorities were quick to praise the school resource officer at Great Mills High, Deputy Blaine Gaskill, who they said responded almost immediately to the gunman and fired his weapon. Deputy Gaskill was unharmed in the exchange.

“He pursued the shooter, engaged the shooter,” Sheriff Timothy K. Cameron of St. Mary’s County said. The officer, he said, then “fired a round at the shooter; simultaneously the shooter fired a round as well.”

But it was not immediately clear, the sheriff said, whether Deputy Gaskill’s shot had struck Mr. Rollins. And while Sheriff Cameron initially suggested that Mr. Rollins had shot both the 16-year-old and the 14-year-old victims, he said later that he was unable to confirm who had injured the 14-year-old, who was transported to a hospital in stable condition.

Neither victim was identified by the authorities. Sheriff Cameron said it seemed a “prior relationship” had existed between the gunman and the female victim, although he did not say what it was.

The sheriff said she was in the intensive care unit “with life-threatening critical injuries.”

The F.B.I. and the Bureau of Alcohol, Tobacco, Firearms and Explosives sent agents to the school and were conducting a trace on Mr. Rollins’s weapon, Sheriff Cameron said.

Deputy Gaskill’s intervention could increase calls for more schools around the country to add school resource officers, who play hybrid roles sometimes described as part security guard, part educator and part counselor. Currently, at least 30 percent of schools in the United States are believed to have such officers.

But some opponents argue that a police presence in schools increases the chances students will be arrested unnecessarily for minor infractions.

There are few statistics on the effectiveness of school resource officers, although the Alabama-based National Association of School Resource Officers pointed to other instances in which it credited the presence of the officers for saving lives.

In a 2013 shooting at Arapahoe High School in Centennial, Colo., that resulted in one student’s death, for example, a school resource officer was credited with preventing more carnage after pursuing the gunman into the school library, where he killed himself, according to Mac Hardy, chief of operations for the association.

Great Mills High, like so many other schools across the country, was already reckoning with school violence in the aftermath of the Florida shooting. There had been new discussions about school safety. There was an ominous Snapchat posting about a possible threat, which stirred worry but was found to be a hoax. Last week, there was a walkout by students calling for stronger gun control measures.

And then, shortly before 8 a.m. on Tuesday, the authorities said, Mr. Rollins pulled out his weapon and opened fire.

“It sounded like a shelf, like something fell,” said Shawnye Willis, 17, who was standing in the hallway, near an art class.

But then he saw a girl fall forward, and collapse on the ground. When she dropped, he said, he knew it was serious. Teachers yelled for students to get into classrooms, and people began to cry.

The principal, Jake Heibel, announced on the loudspeaker that the school was going into lockdown.

Saar Shah, 15, was working on a robotics assignment when he saw the flashing lights of police cars pull up to the school.

“I was thinking about this project,” Mr. Shah said. “I didn’t think my school was going to get shot up.”

Even students who had been deeply involved in gun control activism after the Parkland shooting, like Mollie Davis, who handed out stickers to fellow students during last week’s walkout, were stunned to find themselves at the center of an issue that had seemed urgent but far away.

“I’m part of this now,” said Ms. Davis, 17, outside the nearby Leonardtown High School, where Great Mills students were taken to reunite with their parents. “It’s weird.”

The shooting here was all but certain to spur new questions about the best way to protect schools. Mr. Smith, the superintendent, said Great Mills High and other schools in the district did not have metal detectors, although officials had discussed the possibility of getting them after the shooting in Parkland.

“There is an associated cost related to that, as well as staff,” Mr. Smith said.

Gov. Larry Hogan, a Republican, described the shooting as a call to action. As states around the country considered new gun control and school safety measures in recent weeks, Mr. Hogan proposed putting $125 million into school protection and $50 million to pay for school resource officers. He complained that the State Legislature, which is controlled by Democrats, had not passed legislation to do so.

“It’s outrageous to me that we haven’t taken action yet on something so important as school safety,” Mr. Hogan said.

Alexandra Hughes, chief of staff for Michael E. Busch, the speaker of the state House of Delegates, called the governor’s complaints “unfortunate” and said the Legislature had included $30 million for school safety measures. She said Mr. Hogan had filed the school safety measure late in the session, but that lawmakers had advanced other measures, including a ban on bump stocks, an “extreme risk” law that would allow judges to take weapons away from dangerous persons, and legislation to remove guns from domestic abusers.

Back in Great Mills, some students and parents said the shooting had pushed them to get involved in coming protests for stricter gun control. As Rayshawn Dickens, 38, went to pick up her 16-year-old daughter, Laquana, after the lockdown, she decided she would spend Saturday driving to Washington to join the “March for Our Lives” protest there.