Three middle school students were charged Tuesday with plotting to kill a teacher for disciplining one of them, and bringing a gun to school to carry out their plan, authorities said.

The plot was foiled when the handgun discharged Thursday morning in a bathroom at Maury Middle School (search) as the boys were examining it. The bullet went through a door and hit one of the students in the leg.

"It could have been worse had she not been sick that day," Sheriff David Davenport (search) said of the teacher. "She didn't come to school. So she was very fortunate."

The boys, two 12-year-olds and a 14-year-old, were charged Tuesday in juvenile court (search) with conspiracy to commit murder and possessing a weapon on school grounds, the sheriff said. They face trial and sentencing Sept. 22.

The sheriff refused to identify the teacher, who is still at the school, or the boys. He also declined to say how the teacher had punished one of the boys, apparently only days before.

He said, though, that the boys all gave statements and "admitted some involvement in this plot."

Two of the boys remained in custody while the injured boy was under house arrest.