SAN ANTONIO (Reuters) - A manhunt was underway in Texas on Sunday for a gunman who shot and killed a San Antonio police detective sitting in a squad car during a routine traffic stop outside the city's police headquarters, authorities said.

The shooting unfolded when the suspect pulled his car up behind the parked police cruiser, got out, walked to the patrol car and shot the detective in the head through the window as he was writing a ticket, San Antonio Police Chief William McManus said.

The gunman then reached through the window, fired a second gunshot into the officer, got back in his vehicle and sped away, driving through the parking lot that serves the San Antonio Public Safety Headquarters on the western edge of downtown.

Hours later in Missouri, a St. Louis policeman was shot in the face and critically wounded as he sat in his cruiser at an intersection. That ambush came from someone in a car that pulled up beside the officer's vehicle, opened fire, then fled, police said. They said they had no suspects.

Investigators likewise lacked any immediate clue to the identity of the San Antonio gunman but found no apparent link with the man who had been pulled over, McManus told a late-afternoon news conference.

He also said he did not know the reason for the traffic stop.

The slain officer was identified as police detective Benjamin Marconi, 50, a 20-year veteran of the force.

McManus said no motive for the shooting was readily apparent, though he referred to the ambush killings of police officers in Texas and Louisiana earlier this year.

"This is everyone's worst nightmare," McManus said. "You never want to see anything like this happen. Unfortunately, like Dallas, like Baton Rouge, it's happened here now."

Texas Governor Greg Abbott said in a statement: "Attacks against law enforcement officers will not be tolerated in Texas and must be met with swift justice."

LETHAL FORCE

San Antonio's McManus said police were looking for a man of slim build and dark complexion in his 20s or 30s, possibly with a goatee beard, whose image was captured by security cameras. The gunman made his getaway in a black car with tinted windows.

The suspect was initially described on the department's Facebook account as a black man. A lookout bulletin issued by police after the chief's latest update with reporters referred again to the suspect as black.

McManus did not say whether police believe there was a racial element to the shooting of Marconi.

For the time being, he said all San Antonio officers were being ordered to call for backup whenever they stop a motorist for any reason.

The San Antonio and St. Louis shootings marked the latest in a string of attacks on law enforcement across the country in recent months, at a time of intense public debate over the use of lethal force by police, especially against minorities.

In July, five Dallas police officers were killed when a black U.S. military veteran opened fire in a sniper attack during a protest against police shootings of black men. Days later, a gunman killed three police officers and wounded four others in Louisiana's capital of Baton Rouge.

More recently, an Iowa man who had been ejected by police from a high school football game after waving a confederate flag at black spectators was charged with killing two police officers who were shot in their patrol cars earlier this month in the Des Moines area.

A total of 57 U.S. law enforcement officers have been killed by gunfire so far this year, a 68 percent increase from the same period in 2015, according to the Officer Down Memorial Page, a database of police fatalities in the line of duty.

President-elect Donald Trump, when asked about the events in San Antonio, said the killing was "terrible." During his campaign to win the presidency, Trump sought to portray himself as the "law and order candidate," in part reflecting anger among the electorate over the police killings.