New York (CNN) The man who shot at two New York Police Department officers Saturday and then opened fire inside a precinct Sunday told investigators he did so because he hates cops, a law enforcement official told CNN.

In all, two officers were shot but survived what NYPD Commissioner Dermot Shea said were targeted attempts to assassinate police officers.

"This is not a crime gone bad. This is not a liquor store robbery interrupted, that a tragedy erupts from. This is a premeditated assassination attempt," Shea said.

"By the grace of God we're not planning a funeral," he added.

The suspect is a 45-year-old Bronx resident named Robert Williams, a law enforcement source with direct knowledge of the situation told CNN.

Williams is being represented by a public defender and is expected to be arraigned Monday. CNN has reached out to his attorney, but has not heard back.

The first shooting took place on Saturday night when a man in a black puffer jacket opened fire on two police officers sitting in a van within the confines of the 41st precinct in the Bronx. One officer was wounded and is expected to survive, police said. That officer is expected to be released Monday. The second officer in the van was not hit.

Then on Sunday morning, a man walked into the 41st precinct in the Bronx just before 8 a.m. and opened fire at uniformed officers and a civilian employee, Shea said. One male lieutenant who returned fire was shot in the arm and is in stable condition, Shea said.

The suspect was not shot but lay down on the ground after he ran out of bullets, Shea said. He was then taken into custody.

Videos of the incident were posted on social media, and a senior NYPD official confirmed its contents.

FOOTAGE: Allegedly the shooting of the NYPD Lieutenant this morning inside the 41 Precinct in the Bronx pic.twitter.com/cmO6Bs51Zy — NYC Scanner (@NYScanner) February 9, 2020

"This was an attempt to assassinate police officers," Mayor Bill de Blasio said. "We need to use that word because it was a premeditated effort to kill, and not just to kill other human beings, but to kill those who wear a uniform that represents all of us."

Shea said investigators are confident that the same man opened fire in both incidents.

Police said the suspect had been arrested and convicted in 2002 for attempted murder. In that incident, he shot a person, carjacked a woman, crashed that vehicle and then entered into a gunfight with police officers, Shea said. He was paroled in 2017, but he has since had one recorded arrest and had a scheduled court appearance in the coming days for that arrest, Shea said.

How each shooting unfolded

In the Saturday night shooting, the suspect came up to the two officers sitting in a van with its emergency lights on and asked a question, Shea said. When an officer answered, the shooter pulled out a gun and fired multiple times without provocation, he said.

Shea said the officer in the driver's seat yelled, 'Gun!' when the shooter pulled out a weapon. Neither of the officers returned fire, Shea said.

The officer in the driver's seat was hit in the neck and chin area, narrowly missing the carotid artery, Shea said. The officers were able to drive off, and the suspect fled the scene.

After the first shooting, the official said Williams left and visited family members before going to the 41st precinct office and opening fire, a law enforcement official told CNN.

A video posted on social media shows the incident and was also confirmed by a senior NYPD official.

#BREAKING: Video shows NYPD cops ambushed in the Bronx



pic.twitter.com/SJxM3gV7AQ — NYC Scanner (@NYScanner) February 9, 2020

In Sunday morning's incident, the suspect walked into the precinct and immediately pulled out a gun and fired multiple rounds toward the desk area where several uniformed members were present, Shea said. The suspect then walked into an area beside the desk and fired several more rounds at uniformed service members and a civilian, but those shots hit no one, he said.

Shea said the suspect was then taken into custody and the firearm, a 9 mm Sig Sauer, was secured by police. The incident was captured on video from within the precinct station house.

Shea said this weekend's attacks reminded him of the 2014 murders of officers Rafael Ramos and Wenjian Liu as they sat in their patrol car. In both situations, he said, the attacks came not long after public protests against police practices in the city. Protests against the policing of subway fare evasion January 31 led to the arrests of 13 people, CNN affiliate WCBS reported

"Just remember these things are not unrelated," he said. "We have people marching in New York City last week and I condemned it and I condemn it right here again today -- using profanities against the Police Department.

"Everyone should be speaking out against this, and you have to be careful about the words you use, whether it's on social media or on written papers or speaking, because words matter and words affect people's behavior."