HOUSTON — The man charged with killing a sheriff’s deputy at a suburban gas station Friday emptied his 15-round handgun into the back and the back of the head of the deputy, as witnesses watched in horror and surveillance cameras captured the shooting, prosecutors said Monday.

The man, Shannon Jaruay Miles, 30, walked into a courtroom crowded with sheriff’s deputies and police officers for his first court appearance here Monday morning. Mr. Miles said nothing as the Harris County district attorney, Devon Anderson, described to a judge what the authorities have called an unprovoked attack. The deputy, Darren H. Goforth, 47, had pulled into a Chevron gas station about 8:30 p.m. Friday when Mr. Miles approached him from behind and opened fire, the authorities said.

After the hearing, Ms. Anderson said Mr. Miles was cooperating with investigators but said they were still trying to establish a motive, even though prosecutors do not have to prove one under Texas law. Law enforcement officials have said it appeared Deputy Goforth was targeted because he was wearing a uniform.

After a weekend of denouncing a “dangerous national rhetoric” aimed at the police, officials have been hesitant to comment further and to explain how it might have influenced Mr. Miles. The Harris County sheriff, Ron Hickman, said Saturday, referring to the “Black Lives Matter” slogan, “Well, cops’ lives matter, too.”