BROWNSVILLE, Texas (AP) — Police shot and killed an eighth-year student in the hallway of his middle school Wednesday after the boy brandished what looked like a handgun and pointed it at officers. It turned out to be a pellet gun that closely resembled the real thing.

Fifteen-year-old Jaime Gonzalez “had plenty of opportunities to lower the gun and listen to the officers’ orders, and he didn’t want to,” Interim Police Chief Orlando Rodriguez said.

Shortly before the confrontation, the boy had walked into a classroom and punched a random boy in the nose for no apparent reason, police said. Investigators did not know why he pulled out the weapon.

“We think it looks like this was a way to bring attention to himself,” the police chief said. He said the officers’ actions were justified and no one else was hurt.

Authorities declined to share what the boy said before being shot.

The shooting happened during first period at Cummings Middle School in Brownsville. Teachers locked classroom doors and turned off lights, and some frightened students dove under their desks. They could hear police charge down the hallway and shout for Gonzalez to drop the weapon, followed by several shots.

Two officers fired three shots, hitting Gonzalez at least twice, police said.

The boy’s father, Jaime Gonzalez Sr., said he had no idea where his son got the gun or why he brought it to school.

“We wouldn’t give him a gift like that,” he told The Associated Press from the family’s home, where other relatives and friends of his son were gathering Wednesday night.

He said nothing seemed amiss when he, his wife and their son went out for nachos the night before, then went home and watched a movie. He said he last saw his son Wednesday morning, when the boy said goodbye before leaving to catch the bus to school.

Gonzalez Sr. was struggling to reconcile the day’s events, saying his son seemed to be doing better in school and was always helpful around the neighborhood mowing neighbors’ lawns, washing dogs and carrying his toolbox off to fix other kids’ bikes.

Both he and his wife, Noralva, questioned why police repeatedly shot at their son and called the shooting unjustified.

“Why was so much excess force used on a minor?” he asked. “Three shots. Why not one that would bring him down?”

His wife, who demanded that the officers be punished, added: “What happened was an injustice.”

Rodriguez said his officers “took the necessary action to protect themselves and the other kids.” There weren’t many others in the hall at the time, but “they had every right to take the action that they took.”

The boy’s godmother, Norma Leticia Navarro, said she couldn’t imagine why he would have brought a gun to school.

“I wish I could ask him why he did that, ‘Why did you put yourself in that position?'”

She said she understood that police were doing their job, but she wondered if other steps could have been taken.

“Jaime was not a bad kid,” she said. “I’m not saying he was perfect or an angel, but he was a very giving person.”

David A. Dusenbury, a retired deputy police chief in Long Beach, Calif., who now consults on police tactics, said the officers were probably justified in their actions.

If the boy was raising the gun as if to fire at someone, “then it’s unfortunate, but the officer certainly would have the right under the law to use deadly force.”

Administrators said the school would be closed Thursday but that students could attend classes at a nearby elementary school if they wished.

Superintendent Carl Montoya remembered Gonzalez as “a very positive young man.”

“He did music. He worked well with everybody. Just something unfortunately happened today that caused his behavior to go the way it went. So I don’t know.”

Gina Rangel was in her first-period class in the gym when the school was locked down. She said friends who were closer to the confrontation heard the boy threaten to kill everyone.

Her mother, Irma Rangel, said she was worried about the school’s safety “because if this happened once, kids imitate.”

Brownsville, on Texas’ southern tip, is beset by spillover violence from Mexico’s drug war. As word of the shooting spread through the city, frantic parents rushed to reach their children.

Those who got there early were able to retrieve their kids, but some who arrived later found the street outside the school lined with squad cars and blocked off.

Two hours later, dozens of frustrated parents and relatives flooded out of the park pavilion without their children after school officials announced that all remaining children had been bused to a high school and could be picked up there.

Julie Tomalenas waited for an hour to pick up her 13-year-old sister before being told of the relocation.

“It was very stressful not knowing if she was OK, where she was, when we could see her again,” she said.

___

Associated Press writers Diana Heidgerd and Danny Robbins in Dallas and Mike Graczyk in Houston contributed to this story.