San Antonio police Chief William McManus said the suspect is not known and has not yet been apprehended. A motive is not known.
"This is everyone's worst nightmare," he said.
McManus said the officer had pulled over a vehicle and while he was inside his squad car 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. The man fired a second time, then walked back to his vehicle and drove away, McManus said.
The officer, a 20-year veteran of the force, was pronounced dead at a hospital.
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.
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.