Robert Williams was captured after he walked into a police station on Longwood Avenue in the Bronx and started shooting before 8 a.m. Sunday.
He is charged with 14 counts of attempted murder, as well as criminal possession of a weapon and resisting arrest. In court Monday, he pleaded not guilty and was remanded by the judge.
RELATED: Who is NYPD shooting suspect Robert Williams?
Two security camera videos posted on social media captured the shooting inside the 41st Precinct that left Lieutenant Jose Gautreaux with injuries to his arm.
Other officers returned fire but did not hit the suspect.
One of the videos shows Williams apparently firing at police personnel before he ran out of bullets. He then laid down and slid his pistol across the floor.
Gautreaux was rushed to Lincoln Hospital in stable condition. Another officer was also treated for minor injuries.
"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," New York City Police Commissioner Dermot Shea said at a press conference Sunday.
Gautreaux was released from the hospital to the cheers of his fellow officers Monday afternoon.
"This is a great day," Shea said. "From where we were for the last 24 hours, yesterday with (Officer) Paul (Stroffolino) and then today Jose walking out, springing out of the chair. This is a really good day. We were very lucky. We were very lucky, and we are all grateful."
The first shooting happened just hours earlier, around 8:30 p.m. Saturday, when authorities say Williams opened fire on an NYPD van in the same section of the Bronx.
Another surveillance video shows what appears to be the police van as it was pulling away from shots fired. The video shows a man in black pointing a weapon at the van and is seen with a gun in his hand as he is walking away from the scene.
Stroffolino was behind the wheel and was grazed in the chin and neck, but he avoided serious injury.
He was released from the hospital Sunday morning to the applause of fellow officers.
Sources say Williams was arrested for attempted murder in 2002 and released on parole in 2017. He is described as "a career criminal."
In a 2002 case, he shot a person, carjacked a woman, crashed her vehicle, and then got into a shootout with police, according to officials. Police are currently going through his arrest history.
A woman is also being interviewed in connection to Sunday morning's shooting, but Shea indicated she is not being treated as a suspect and it was believed Williams duped her into driving him to the precinct.
Shea said at a late-night news conference that the attack "should outrage all New Yorkers" and called the shooting an "attempted assassination."
He 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 that the protests helped create an anti-police environment.
"These things are not unrelated," he said. "We had people marching through the streets of New York City recently. 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 while police had a right to protest, 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."
Governor Andrew Cuomo also released a statement regarding the two attacks.
"I am horrified by the two attacks on NYPD officers that occurred last night and this morning in the Bronx. Members of New York's law enforcement community put their lives on the line every day to keep us safe, and they deserve our respect and appreciation. I have asked the New York State Police to reach out to the NYPD to offer any assistance necessary. We have zero-tolerance for attacks of any kind against law enforcement, and the person or people responsible will be held accountable to the fullest extent of the law."
The Police Benevolent Association of the City of New York responded with a statement as well.
"It is a double miracle that we are not preparing for two funerals right now. These targeted attacks are exactly what we have warned against, again and again. The hatred and violence directed at cops continue to grow. Good luck and kind words are not enough to keep police officers or the public safe. Our elected officials need to start listening to us and working with us - not against us - to fix the deteriorating environment on our streets."
Robert Gangi, executive director of the Police Reform Organizing Project advocacy group, pushed back against the criticism aimed at protests, and said it was "irresponsible" for Shea and de Blasio to say the shooter's behavior "is a result of the demonstrations and protesters who are protesting in a legitimate fashion."
Of the shooter, Gangi said there is "no defense for a lunatic who opens fire on police."
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. Shea said Ramos and Liu's deaths were "not something that engenders anything but the worst memories."
Some information from the Associated Press
* More Bronx news
* Send us a news tip
* Download the abc7NY app for breaking news alerts
* Follow us on YouTube