A Maryland high school student who fatally shot his ex-girlfriend and injured another student outside a classroom last week killed himself when a school resource officer stationed on campus confronted him, the authorities said on Monday evening.

The shooting at Great Mills High School in Southern Maryland last Tuesday was over in about a minute. Just before the first class period started, Austin Wyatt Rollins pulled out his father’s handgun in a hallway and fired one shot. It struck his former girlfriend, Jaelynn Willey, in the head and the other student, Desmond Barnes, in the leg. Moments later, Mr. Rollins, 17, was dead in another part of the school.

But before Monday, it was not clear whether the gunman had killed himself or whether the resource officer, Deputy Blaine Gaskill, fatally shot him. The St. Mary’s County Sheriff’s Office said its investigation had found that Mr. Rollins fired one shot at Jaelynn, 16, and then one more into his head at the same time Deputy Gaskill fired his weapon.