RIGBY — A sixth-grade girl brought a gun to her middle school, shot and wounded two students and a custodian and then was disarmed by a teacher, authorities said.

The three were shot in their extremities during the 9:15 a.m. Thursday incident at Rigby Middle School and are expected to survive, officials said at a Thursday afternoon news conference. All three victims were transported via ambulances to Eastern Idaho Regional Medical Center in Idaho Falls following the shooting.

“Today we had the worst nightmare a school district could encounter,” Jefferson School District Superintendent Chad Martin said Thursday following the incident.

Jefferson County Sheriff Steve Anderson says the girl pulled a handgun from her backpack and fired multiple rounds inside and outside Rigby Middle School in Rigby, an East Idaho city located between Idaho Falls and Rexburg.

A female teacher disarmed the girl and held her until law enforcement arrived and took her into custody, authorities said, without giving other details. Authorities say they’re investigating the motive for the attack and where the girl got the gun.

The girl is a Rigby Middle School student who resides in Idaho Falls, Anderson said. Her name has not yet been released.

The teacher who stopped the shooting was identified in the Life in Rigby Facebook group as Krista Turnblom Gneiting. She is listed as an eighth-grade math teacher on the Rigby Middle School’s website.

Gneiting posted the following comment on Facebook thanking the community for its support: “My heart is touched by all the incredible outpouring of love I’ve received. Thank you. I don’t want money, I just appreciate the incredible support of Rigby!!! I love my students so much! It is why I teach!! They make my heart happy every every day!!!! All of the staff at Rigby did their part and kept our wonderful children safe! Thank you! I love you all and we will get through this together.”

Dr. Michael Lemon, trauma medical director at EIRMC, said the injured adult male custodian was treated and released for a bullet wound in an extremity. The bullet went cleanly through the limb, Lemon said.

Authorities said the custodian, who’s been identified as Jim Wilson, was shot when he placed himself between the shooter and the two students who were wounded.

An online fundraising campaign has been started to help Wilson pay for his medical expenses. Donations can be made at gofund.me/04e47614. As of 7:30 p.m. Thursday over $9,700 had been raised for the custodian.

Both of the students who were shot are being held at EIRMC overnight and one of them might need surgery, Lemon said. Still, both students are in fair condition. One of the students had wounds in two limbs and might have been shot twice, Lemon said. The wounded students’ names have not been released.

Police were called to Rigby Middle School around 9:15 a.m. Thursday after students and staffers heard gunfire. Multiple law enforcement agencies responded, and students were evacuated to the nearby Rigby High School to be reunited with their parents.

Lucy Long, a sixth-grade student at Rigby Middle School, shared her experience from inside the school with the Post Register. She said she heard two gunshots and then her classroom was placed under lockdown with all the lights and computers turned off and the students lining up against the classroom wall.

Lucy said she was comforting her friends and began recording, so police would know what happened if the shooter came in. The audio contained mostly whispers, with one sentence audible.

“It’s real,” one of the students is heard saying.

Lucy’s father, Seth Long, said he got a text from his wife around 9:18 a.m. Thursday telling him the school was on lockdown. Parents, concerned for their children’s safety, were just pouring in as he arrived, he said.

Lucy said the lockdown ended around 10 a.m. Thursday. She said she saw blood on the hallway floor when police escorted her and other students out of the classroom.

Trent Tomita was at work when his daughter, Raylee, called him from Rigby Middle School during the shooting.

“She said there was a girl shooting in the school and she didn’t know what to do,” Trent said. “She said, ‘Tell me what to do.’”

Raylee and other students had exited the school to escape the shooting and weren’t sure where to go, Trent said.

Trent said he told her they needed to run as fast as they could to Dansie Hepworth Dental across the street. Trent left work and headed for his daughter.

Trent stated that when he arrived at the dental office, police officers were already on the scene at the school.

Yandel Rodriguez, age 12, was another student at Rigby Middle School when the shooting occurred.

“Me and my classmate were just in class with our teacher — we were doing work — and then all of a sudden, there was a loud noise and then there were two more loud noises. Then there was screaming,” Yandel said. “Our teacher went to check it out and he found blood.”

All Friday classes have been canceled in the Jefferson School District because of the shooting but counselors will be available from 8 a.m. to 4 p.m. Friday at Rigby High School. Classes will resume on Monday.

Rigby Middle School has about 1,500 students in sixth through eighth grades, according to the National Center for Education Statistics.

“I am praying for the lives and safety of those involved in today’s tragic events,” Gov. Brad Little said in a prepared statement. “Thank you to our law enforcement agencies and school leaders for their efforts in responding to the incident.”

Following the shooting police tape surrounded Rigby Middle School and small evidence markers were placed next to spots of blood on the ground. Investigators interviewed the school’s faculty and staffers individually.

Thursday’s shooting was not the first school shooting in the state but it appears to have been the most serious in terms of injuries. It also was not the first time that gun violence has affected the Jefferson School District.

In February 1989, a 14-year-old male at Rigby Junior High School threatened a teacher with a handgun and took a female student hostage. A Post Register article from the time said students were locked down for about an hour and the boy was taken into custody without any shots fired.

The last shooting at any Idaho school occurred in Twin Falls in 2016, when a student brought two stolen guns into Robert Stuart Middle School and accidentally fired one of them. No one was injured in that incident.

In 1999, a student snuck a shotgun into Notus Junior-Senior High School in Canyon County. The student fired two shots, including one that blasted a hole through a steel gymnasium door, but no serious injuries were reported.

Pocatello Police Chief Roger Schei said that in 1997 shots were fired at an alternative school in the Gate City but no one was injured.

He said Thursday’s shooting at Rigby Middle School will definitely cause his officers to be more vigilant and aware.

“It’s something we’re always monitoring for — situations like that,” Schei said. “Unfortunately, it has happened multiple times in our country.”

Pocatello police train constantly so they’re prepared for incidents such as school shootings, Schei said.

“It’s just a sad incident anytime people come to violence, especially in any school, which is supposed to be a safe place,” Schei added. “Anytime (we have something) like this it greatly concerns everybody involved. I’m glad there was no tragic loss of life and the person was taken into custody safely.”

American Falls School District Superintendent Randy Jensen said there was an increased police presence at his district’s schools on Thursday because of the shooting.

“We’ve always felt like we’re a little immune to it,” Jensen said. “We all have to do the best we can to prevent it.”

The Post Register and Jefferson Star contributed to this story.