Shannon Miles was picked up for questioning early on Saturday following the Friday night shooting, which was captured on surveillance video, Harris County Sheriff Ron Hickman told reporters. He noted that Miles is black and has a history of prior arrests for trespassing and resisting arrest.
Earlier on Saturday, Hickman had linked the shooting of deputy Darren Goforth, who was white, to anti-police rhetoric across the country in the wake of deaths of unarmed black men at the hands of white officers.
On announcing the charges against Miles later in the day, Hickman said the department assumed that Goforth was "a target because he wore a uniform."
"We have not been able to extract any details regarding a motive at this point," Hickman added. "As far as we know, deputy Goforth had no previous contact with the suspect, and it appears to be clearly unprovoked."
Hickman said a handgun had been recovered and that a ballistics test matched it to bullets recovered from the scene.
Goforth, a 10-year veteran of the force, was pumping gas into his patrol car when the gunman approached from behind and shot him in the back, then shot him more times as he lay on the ground, sheriff's officials said.
The fatal shooting in Houston comes more than eight months after two New York police officers were ambushed and shot to death in Brooklyn by a gunman who had said he wanted to avenge the deaths of black men in confrontations with police.
New York Police Commissioner William Bratton said at the time of the shooting, which followed large-scale protests over deaths of African-Americans at the hands of officers, that police were unfairly subjected to public anger.
Hickman was blunt in his defense of law enforcement in the midst of protests against police by movements such as Black Lives Matter, which has complained of police violence and mass incarceration of blacks.
"We've heard black lives matter; all lives matter. Well cops' lives matter too," Hickman said.
"Our system of justice absolutely requires a law enforcement presence to protect our communities, so at any point where the rhetoric ramps up to the point where calculated cold-blooded assassination of police officers happen(s), this rhetoric has gotten out of control," Hickman added.
Some commentators on social media objected to Hickman's statements.
"When Blacks get legally killed we are constantly told it's not about race. But the sheriff in the DarrenGoforth case IMMEDIATELY invoked race," tweeted African-American author and lecturer Tariq Nasheed.