Sheriff Tim Fulton said the boys intended to harm the young girl because she had teased two of them.
The plot included a .22-caliber revolver, a knife and a box of bullets that were all hidden on the playground, authorities said.
The boys, whose names were not immediately released, apparently brought the weapons to school Wednesday morning, prosecutor Michael Hayworth said. The intent was to assault the girl over the recess hour that day, he said.
"From the interviews I don't believe that they fully comprehended the full significance of their actions," Hayworth said. "But they understood that this was going to bring harm to her."
Fulton said an 8-year-old classmate of the two younger boys was the one who alerted the school of the plot.
"I need to commend that young man for such a brave act," the sheriff said. "He saved the lives of who knows how many people."
Fulton said one of the 8-year-olds apparently brought the gun from home.
Forsyth is about 100 miles east of Billings. The school has about 200 students in kindergarten through the sixth grade.
"Needless to say, it is a frightening experience for a community and our schools," Superintendent Dave Shreeve said. "We believe it's an isolated incident but it does bring into reality that this can happen in any place at any time."