The object in his hand turned out to be a pellet gun.
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.
Officials said a school administrator at Cummings Middle School saw the student, identified as Jaime Gonzalez, carrying what looked like a gun and called Brownsville and school district police.
School district spokeswoman Drue Brown said when police arrived, Gonzalez "engaged" the officers and was subsequently shot. He was pronounced dead at a hospital.
Shortly before the confrontation, authorities say Gonzalez walked into a classroom and punched a random boy in the nose for no apparent reason.
The school, with an enrollment of about 750 students, was immediately placed on lockdown. Gonzalez did not threaten students or teachers, and no one else was hurt.
Miguel Grimaldo, a seventh-grader who said he was two classrooms from where the shooting took place, said the school was already on lockdown when he heard three shots fired.
Grimaldo, 12, said students later followed police out of the building and boarded buses that took them to a neighboring park, where his mother picked him up.
The Associated Press contributed to this report.