The police killed an armed student after an active shooter had been reported near a middle school in Mount Horeb, Wis., on Wednesday, the authorities said.

No other students or police officers were injured during the threat, Josh Kaul, the Wisconsin attorney general, said at a news conference.

“This could have been a far worse tragedy,” Mr. Kaul said.

The authorities did not identify the person killed, but they said the student was a male, and a minor, who attended a Mount Horeb Area School District school. It was unclear what type of weapon the student had.

Officers with the Mount Horeb Police Department fired shots at the armed student, Mr. Kaul said. It was unclear whether the student fired back at the officers.

The Associated Press reported that witnesses described hearing gunshots and seeing dozens of children running.

Earlier in the day, the Mount Horeb Area School District said in a post on Facebook that there had been “an active shooter near our middle school this morning,” adding that the person had not entered the school.

Steve Salerno, the district’s superintendent, said at the news conference that the episode was “any parent’s nightmare.”

“It’s an out-of-body experience, quite frankly,” Mr. Salerno said.

The Wisconsin Department of Justice said it had opened an investigation into “the entirety of the incident,” adding that the officers involved were wearing body cameras.

Before the news conference, the district in Mount Horeb, a village of 7,600 residents, about 20 miles southwest of Madison, said that an initial search of the middle school had not turned up any additional suspects.

“As importantly, we have no reports of individuals being harmed, with the exception of the alleged assailant,” the district said. Schools in Mount Horeb were in “hard lockdown,” the district said, as police officers circulated through the middle school.

The district initially urged parents not to come to the middle school for their children.

“Students will remain in buildings while the police continue their investigation,” the district said, adding that “reunification will take time and will be done in stages.”

Mr. Kaul said that the reunification was still ongoing on Wednesday night, after the district had said it would begin dismissing students at 5 p.m. local time.

Melissa Alvarado told WMTV, a Wisconsin television station, that she was at work when her children called her to say that there had been a shooting. “Getting that call and not knowing, are they going to make it? Is this going to be our last phone call?” she said. “It’s hard.”

The school district will not have classes on Thursday, Mr. Kaul said, adding that he hoped classes would resume on Friday.

In a joint statement, the village of Mount Horeb and the Mount Horeb Area Chamber of Commerce expressed gratitude to the police and to local businesses that provided a safe space for students to shelter.

Gov. Tony Evers of Wisconsin said that he was closely monitoring the situation.

“I am praying for the health and safety of our kids, educators, and staff and grateful for the first responders who are working quickly to respond,” he wrote on social media.

Joe Parisi, the Dane County executive, said in a statement that “moments like this turn lives upside down, cause trauma, sorrow, and a moment of reflection for all of us.”