A gunman who ambushed police officers in the Bronx twice in 12 hours has been arrested.
The man, who has not been named, was captured after he walked into a police station and started shooting shortly before 8am on Sunday.
He wounded one officer and narrowly missed a number of others before he ran out of bullets, lay down and gave up his gun.
That attack came just hours after the same man approached a police van in the same part of the Bronx and fired at two officers inside.
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.
“The coward from this morning’s shooting is in police custody. At this time, we are confident that he is the same person who attempted to assassinate our police officers last night.”
More from New York
Storm Ciara helps British Airways flight break transatlantic record
Harvey Weinstein’s lawyers demand his rape trial is moved out of New York City
Harvey Weinstein arrives on walking frame for start of rape trial – as new charges filed
New York stabbings: Hanukkah attack on rabbi’s home ‘an act of domestic terror’
Bristol girl dies on school trip to New York
Babe Ruth’s 500th-home run bat sells for $1m
He also hit 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.
“These things are not unrelated. We had people marching through the streets of New York City recently.
“Words matter. And words affect people’s behaviour.”
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 got out of hand.
“Anyone who spews hatred at our officers is aiding and abetting this kind of atmosphere,” he said.
“It is not acceptable. 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.”
Robert Gangi, executive director of the Police Reform Organising Project, said it was irresponsible” to say the violence was linked to the recent demonstrations.
Mr Gangi said there is no defence for a “lunatic who opens fire on police”.
The first attack happened just before 8:30pm on Saturday, when the gunman walked up to the van asking the officers for directions and then fired shots.
Police released a photograph of the suspect only for him to walk into the police station co-ordinating the manhunt and opened fire.