GREAT MILLS, Md. -- The student who fatally shot a female classmate last week at a Maryland high school died from a self-inflicted gunshot wound during a confrontation with a school resource officer who also fired his gun, authorities said Monday. The St. Mary's County Sheriff's Office said in a statement that 17-year-old Austin Rollins fired a fatal shot to his head just as he encountered sheriff's deputy Blaine Gaskill. The shot fired by Gaskill struck the gun in Rollins' hand, the sheriff's office added.

The shooting occurred last Tuesday at Great Mills High School, about 65 miles southeast of Washington. Jaelynn Willey, 16, died two days later after being taken off life support. Her funeral service is scheduled for Friday. The sheriff's office said Rollins and the girl had been in a relationship that recently ended.

Desmond Barnes, 14, who was shot in the thigh, was released from a hospital a day after the shooting.

Get Breaking News Delivered to Your Inbox

New details released by the sheriff's office show how Rollins died. The sheriff's office also released a timeline of the incident and 911 calls from adults and students, including the 14-year-old who survived.

According to the sheriff's office, Rollins entered the main entrance of the school the day of the shooting about five minutes before he shot Willey in the head with his father's gun. The same bullet traveled into the leg of Desmond Barnes, who had sought shelter in a classroom.

Rollins then turned a corner and passed several classrooms before the confrontation with the school resource officer, which occurred about three minutes after shooting Willey, the sheriff's office said. Rollins and Gaskill fired their weapons about 30 seconds later.

Gaskill, a six-year veteran with SWAT team training, was unharmed, reports CBS Baltimore.

In one of the 911 calls released, Barnes tells a dispatcher, "I was just shot in my school."

Austin Rollins is seen in photo obtained by CBS News.

A woman, possibly a teacher, gets on the phone and tells the dispatcher that four students are inside her classroom, one of them shot and bleeding.

"We have him laying down," she said. "I'm afraid to transport him to safer place."

For the next several minutes, the woman talks to the dispatcher or is heard talking to Barnes. A voice on the school's intercom system urges students to stay in their classrooms.

"It'll be OK," the woman can be heard saying. "It's OK ... They're coming. They're coming. Don't worry."

Barnes and the dispatcher talk again. The teen said he's been shot in the back of the thigh and that "it's burning."

"Oh my knee hurts so bad," he said.

"We're getting help to you Desmond," the dispatcher replied. "Stay strong for me buddy."

Emergency responders soon arrive.

"Hi Desmond, we're putting a tourniquet on you, all right?" one of them is heard telling him. "A tourniquet stops the bleeding."

Another person who called 911 from the school, possibly a teacher, tells a dispatcher that she heard a single gunshot and saw a girl bleeding outside the classroom.

"We're hiding behind my desk," the caller said before counting each of the 11 students with her, one by one.