San Antonio Police Chief William McManus said the officer, Benjamin Marconi, 50, was killed late Sunday morning. He says the suspect has not yet been apprehended and a motive is not known.
VIDEO: Tom Koch has the latest on a San Antonio officer's fatal shooting
McManus says Marconi had pulled over a vehicle and while he was inside his vehicle writing a ticket, a vehicle pulled up behind him. He says the driver of that vehicle got out, walked up to the officer's driver-side window and shot the officer in the head.
Police released a photo of a person seen on surveillance video that is believed to have information about the crime.
"This is everyone's worst nightmare," he said.
Marconi was pronounced dead at a hospital. He was a 20-year veteran of the police force.
McManus said, "I think that the uniform was the target, and anyone who happened along was the person he targeted."
Police are looking for a black car with a driver wearing a hoodie, baggy pants and a beard, police said.
Police interviewed several people overnight, but say they are still looking for any information that will lead them to the suspect.
The shooting came less than five months after a gunman killed five officers in Dallas who were working a protest about the fatal police shootings of black men in Minnesota and Louisiana. It was the deadliest day for American law enforcement since Sept. 11, 2001.
Statement on murder of San Antonio Police Officer pic.twitter.com/m1WrgMaFva— Gov. Greg Abbott (@GovAbbott) November 20, 2016
Ten days after the Dallas attack, a man wearing a ski mask and armed with two rifles and a pistol killed three officers near a gas station and convenience store in Baton Rouge, Louisiana. And earlier this month, two Des Moines, Iowa-area police officers were fatally shot in separate ambush-style attacks while sitting in their patrol cars.
"It's always difficult, especially in this this day and age, when police are being targeted across the country," McManus said.
Angela and I join with all Texans as we grieve the loss of a courageous San Antonio police officer. Our prayers are with his family.— Ken Paxton (@KenPaxtonTX) November 20, 2016
"Our prayers go out to the family of Detective Benjamin Marconi, who was shot and killed today during a routine traffic stop outside of the San Antonio police headquarters," Senator Ted Cruz said Sunday. "To the San Antonio Police Department and law enforcement officers all across the State of Texas, our message is clear: we stand unequivocally with you, and we will not tolerate those who viciously and deliberately target law enforcement."