A 14-year-old boy was taken into custody Tuesday after holding 29 students and a teacher hostage at a West Virginia high school, state police said.

Authorities said the boy took a pistol into a second-floor classroom at Philip Barbour High School in Philippi, before surrendering after negotiations with police, State Police Lt. Michael Baylous said in a statement. No injuries were reported in the incident.

Barbour County Schools Superintendent Jeffrey Woofter credited the unidentified teacher for maintaining control when classes were about to change and praised the Philippi police chief for talking the suspect, whom Woofter called a "very troubled young man", into giving up.

Woofter said the teacher talked the boy into not allowing the next group of students to enter the classroom.

"The teacher did a miraculous job, calming the student, maintaining order in the class," Woofter said.

Students who opened the door to enter for the next class were asked to leave. Those students went across the hall to alert another teacher, who then alerted school officials. An assistant principal raced to the hallway outside the classroom, then called the office asking that police be alerted, Woofter said.

Kayla Smith, a 17-year-old senior, said initially no one in her classroom in another area of the school took a "code red" warning seriously.

"Then we all held hands and said a prayer," she said.

Local authorities received a call about a report of someone with a gun about 1:30 p.m. local time Tuesday, placing the school was placed on a lockdown, while students elsewhere in the school were moved to a nearby football field, accounted for and sent home by school bus. Authorities said police had brought the situation under control by about 3:30 p.m. though they didn't immediately say just for how long hostages were held.

After initial negotiations, the suspect agreed to release the students and teacher, then eventually put the gun down and surrendered without further incident, Baylous said.

Barbour County Prosecutor Leckta Poling said she plans to pursue unspecified charges against the suspect, who was taken to a hospital for evaluation. Poling said that because the case involves a juvenile, the court process would be closed. Police haven't identified the student.

Steve Saltis was among several anxious parents who went to the school and waited outside an area cordoned off by police tape for students to be released. Saltis said by phone that his daughter attends the school and that "a lot" was going through his mind while he waited for her to head home.

Saltis said many students had been sitting in the football stadium after the school was evacuated and that he was able to talk to his daughter. But Saltis said law enforcement officials told parents nothing while the suspect was still in the school.

"I think that's the scariest I've been in a long time," Saltis said later.

Woofter, a former sheriff who began his new job as schools superintendent in July, credited parents for heeding police warnings to stay away from the school.

"In such a trying time, I was just amazed at our parents and how everybody responded to the situation," Woofter said. "I just thank God everybody is safe and hopefully we'll never have a repeat of that again."

State Police Capt. Dave Reider said there will be an increased law enforcement presence at the school on Wednesday when classes resume. He said the school will be open but the start of classes will be delayed by two hours.

Tuesday was the ninth day of the new school year in Philippi, a town of some 3,000 residents located about 115 miles south of Pittsburgh, Pennsylvania.

The Associated Press contributed to this report.