BROWNSVILLE, Texas – Police shot and killed an eighth-grader 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.

The 15-year-old “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 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.

The boy, identified as Jaime Gonzalez, did not threaten students or teachers, and no one else was hurt.

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

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

The shooting happened as classes were about to begin 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 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.” 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.”