A "coward" ex-con was taken into custody Sunday in New York City after two police officers were shot less than 12 hours apart in ambushes described as assassination attempts by the mayor and police commissioner.

Lt. Jose Gautreaux was in stable condition after being wounded Sunday morning in shooting caught on video at a Bronx precinct headquarters, Police Commissioner Dermot Shea said. Shea said a man taken into custody at the scene was also suspected in the previous attack on officers in a police van a few blocks away.

Mayor Bill de Blasio, speaking at a news conference Sunday, said Gautreaux was in stable condition. The officer shot Saturday night, Paul Stroffolino, was released Sunday from Lincoln Hospital as a phalanx of officers saluted and cheered.

"Thank God our officers are alive," de Blasio said. "This was an attempt to assassinate police officers, we need to use the word. It was a premeditated effort to kill."

De Blasio called any attack targeting a police officer "an attack on all of us. It's intolerable, and we will not accept it." Shea blamed criticism of police and demands for criminal justice changes for creating an atmosphere that fails to discourage attacks on officers.

“We've had people marching through the streets of New York City recently,” Shea said. “Words matter and affect people’s behavior.”

Gov. Andrew Cuomo issued a statement saying he was "horrified" by the "heinous" attacks and promising that the attacker would be brought to justice. President Donald Trump, on Twitter, took shots at Cuomo and de Blasio.

Trump tweeted that he grew up in the city and appreciated the great work by police.

"Now, because of weak leadership at Governor & Mayor ... and lack of support, our wonderful NYC police are under assault," Trump tweeted. "Stop this now!"

Shea said video from the Bronx precinct headquarters shows the man walking in at about 8 a.m. Sunday, pulling out a gun and shooting multiple rounds toward the main desk area. The gunman then walked into an area around the desk and fired more rounds.

Surveillance video posted on social media shows a man walking into precinct headquarters, then ducking around a corner and returning with a gun drawn before diving onto the floor. Another angle shows an officer ducking for cover behind a desk.

The video does not appear to show the actual shooting.

"In this chaos, the lieutenant, struck in the upper left arm, returned fire" but did not hit the suspect, Shea said. "This coward immediately laid down, but only after he ran out of bullets."

Florida trooper fatally shot: Was assisting motorist on I-95

Shea said the man had a history of violent crime. He had been released from prison in 2017 after serving time for an attempted murder conviction from a 2002 shooting, Shea said. In that case, the suspect had carjacked a vehicle, crashed it and then engaged police in a shootout before being taken into custody, Shea said.

The commissioner said he was confident that ballistic tests would show that the suspect committed both shootings.

"This is not a crime gone bad, not a liquor store robbery interrupted," Shea said. "These were premeditated assassination attempts."

Shea, describing the shooting Saturday night, said two officers were in a marked van with its lights flashing at about 8:30 p.m. when the incident began. Shea said the police van was parked in an area that had been the scene of recent shootings and drug activity.

The man walked up and began speaking with the officers, possibly asking directions, Shea said. Then, "without provocation," the man pulled out a gun and opened fire.

Several shots were fired into the van," Shea said, and one officer was shot in the chin and neck. The officers drove off without returning fire. The wounded officer could be released as soon as Sunday, police said.

"By the grace of God, we are talking about an officer who will be going home," Shea said. "It is a miracle that we are not here under worse circumstances."

Maryland cop charged with murder: Handcuffed man shot in police car

De Blasio called such attacks "unacceptable" – in New York or anywhere.

"I want New Yorkers to be clear, this was an attempt to assassinate police officers," de Blasio said. "There is too much hatred out there, too much hatred in general and too much hatred directed at our officers."