This is an archived article and the information in the article may be outdated. Please look at the time stamp on the story to see when it was last updated.

NEW YORK (AP) — A gunman is in custody after he ambushed police officers in the Bronx twice in 12 hours, wounding two in attacks that ignited outrage from officials who blamed the violence on an atmosphere of anti-police rhetoric.

The man, whose name was not immediately released, was captured after he walked into a police station in the Bronx and started shooting shortly before 8 a.m. Sunday. His shots struck a lieutenant in the arm and narrowly missed other police personnel before he ran out of bullets, lay down and tossed his pistol.

That attack came just hours after the same man approached a patrol van in the same part of the Bronx and fired at two officers inside, wounding one before escaping on foot, police said.

Despite multiple shots fired in both incidents, nobody was killed, and all are expected to recover, police said.

“It is only by the grace of God and the heroic actions of those inside the building that took him into custody that we are not talking about police officers murdered inside a New York City police precinct,” Police Commissioner Dermot Shea said at a news conference.

The officer injured in the first shooting, Paul Stroffolino, was released from the hospital Sunday to applause from a sizable contingent of fellow officers. The officer, a bandage visible on his neck, gave a thumbs-up to the crowd.

Shea called the gunman a “coward” and said he had a lengthy criminal history, including a 2002 shooting and carjacking in which he also fired a gun at police officers. Shea said the man was paroled from prison in 2017 after an attempted murder conviction.

The commissioner also lashed out at criminal justice reform activists who have held demonstrations against excessive force by police in recent months, including a large protest in Grand Central Terminal. He suggested the protests helped create an anti-police environment.

“These things are not unrelated. We had people marching through the streets of New York City recently,” Shea said. “Words matter. And words affect people’s behavior.”

Shea didn’t offer any evidence that the gunman in this weekend’s attacks knew of those protests or was influenced by them.

Mayor Bill de Blasio, who won office partly on a promise to reform overly aggressive policing of minority communities, also suggested that anti-police sentiment had gotten out of hand.

“Anyone who spews hatred at our officers is aiding and abetting this kind of atmosphere; it is not acceptable,” de Blasio said. “You could protest for whatever you believe in, but you cannot vilely attack those who are here to protect us. It creates this kind of dynamic.”

The attacks recalled other unprovoked assaults on police officers sitting in their patrol vehicles.

In 2017, a gunman killed Officer Miosotis Familia as she sat in her patrol vehicle in the Bronx. In 2014, two officers, Rafael Ramos and Wenjian Liu, were shot dead in their patrol car in Brooklyn by a man upset about recent police killings of unarmed black men.

The killings of Ramos and Liu had also followed large street protests and some officers blamed de Blasio for expressing solidarity with the demonstrations, and turned their backs on the Democrat at the funerals.

Robert Gangi, executive director of the Police Reform Organizing Project advocacy group, said it was “irresponsible” for Shea and de Blasio to say the violence this weekend was linked to the recent demonstrations, which he said involved activists “protesting in a legitimate fashion.”

Of the gunman, though, Gangi said there is “no defense for a lunatic who opens fire on police.”

The first attack happened just before 8:30 p.m. Saturday, when the gunman walked up to the van asking the officers for directions and then fired shots, grazing Stroffolino, who was behind the wheel, in the chin and neck and narrowly missing an artery.

Stroffolino and his partner for eight years, Brian Hanlon, a friend since middle school, hit the gas to get away. Neither fired a shot.

Police released a photograph of the suspected shooter and were combing the city for him when he walked into the police station coordinating the manhunt, strolled to the desk and pulled a gun. The wounded lieutenant returned fire but missed, and police personnel dashed out of an adjoining room just in time to avoid the pursuing gunman. Two security cameras captured video of the chaotic scene.

Gov. Andrew Cuomo said in a tweet Sunday he was “horrified by the multiple attacks” on police.

“NY’s law enforcement officers put their lives on the line every day to keep us safe,” he wrote. “These attacks are heinous.”

President Donald Trump immediately used the shootings to assail New York’s Democratic mayor and governor.

“I grew up in New York City and, over many years, got to watch how GREAT NYC’s ‘Finest’ are. Now, because of weak leadership at Governor & Mayor, stand away (water thrown at them) regulations, and lack of support, our wonderful NYC police are under assault. Stop this now!” he tweeted.

The attacks happened in the Bronx’s 41st Precinct, a once crime-plagued district whose former headquarters was infamously branded “Fort Apache” and was the subject of a 1981 film starring Paul Newman.

In recent years, though, the neighborhood has gotten much safer. There were five killings reported in all of last year and 164 robberies, down from 44 killings and 1,095 robberies in 1990.