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

The three victims were shot in their limbs and expected to survive, officials said at a news conference. 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 the small city of Rigby, about 95 miles (145 kilometres) southwest of Yellowstone National Park.

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.

"We don't have a lot of details at this time of 'why' -- that is being investigated," Anderson said. "We're following all leads."

The girl is from the nearby city of Idaho Falls, Anderson said. He didn't release her name.

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

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

Yandel's mom, Adela Rodriguez, said they were OK but "still a little shaky" from the shooting as they left the campus.

Both of the students who were shot were being held at the hospital, and one of them might need surgery, said Dr. Michael Lemon, trauma medical director at Eastern Idaho Regional Medical Center.

Still, both students were in fair condition and could be released as early as Friday. One of the students had wounds in two limbs and might have been shot twice, he said.

"It's an absolute blessing" that they weren't hurt worse, Lemon said. The adult was treated and released for a bullet wound that went through an extremity, the doctor said.

Schools would be closed districtwide to give students time to be with their families, and counsellors would be available starting Friday, said Jefferson School District Superintendent Chad Martin.

"This is the worst nightmare a school district could ever face. We prepare for it," Martin said, "but you're never truly prepared."

Police tape surrounded the school, which has about 1,500 students in sixth through eighth grades, and small evidence markers were placed next to spots of blood on the ground.

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

Lucy Long, a sixth-grader at Rigby Middle School, told the Post Register newspaper in Idaho Falls that her classroom went into lockdown after they heard gunshots, with lights and computers turned off and students lined up against the wall.

Lucy comforted her friends and began recording on her phone, so police would know what happened if the shooter came in. The audio contained mostly whispers, with one sentence audible: "It's real," one student said.

Lucy said she saw blood on the hallway floor when police escorted them out of the classroom.

Jefferson County Prosecutor Mark Taylor said decisions about criminal charges wouldn't be made until the investigation is complete but that they might include three counts of attempted murder.

The attack appears to be Idaho's second school shooting. In 1999, a student at a high school in Notus fired a shotgun several times. No one was struck by the gunfire, but one student was injured by ricocheting debris from the first shell.

In 1989, a student at Rigby Junior High pulled a gun, threatened a teacher and students, and took a 14-year-old girl hostage, according to a Deseret News report. Police safely rescued the hostage from a nearby church about an hour later and took the teen into custody. No one was shot in that incident.

------

Associated Press writers Keith Ridler in Boise and Emily Wilder in Phoenix contributed. Photographer Natalie Behring contributed from Rigby.

Correction:

This story has been updated to correct the spelling of Yandel Rodriguez's first name and his pronouns.