Hundreds of New York City police officers packed the hallways of the Bronx Criminal court as the man accused of opening fire and injuring two cops in back-to-back incidents over the weekend was arraigned on 27 counts of attempted murder in the first and second degree, as well as several other charges.

"Be aware. ... You're in danger," Police Benevolent Association president Patrick Lynch warned officers at a press conference on Monday. "You need to be careful, but more importantly, we need to back each other up."

DEAN CAIN SAYS NYC POLICE ATTACKS ARE ENCOURAGED BY DE BLASIO'S ANTI-POLICE RHETORIC

The suspected gunman, Robert Williams, allegedly ambushed two uniformed police officers who were sitting in a patrol van on Saturday night, shooting and wounding one officer after a bullet grazed his chin and neck, narrowly missing his carotid artery. Neither officer returned fire.

About 12 hours later, police say Williams then opened fire inside police headquarters at the 41st Precinct in the Bronx on Sunday morning. During the rampage, he struck a police lieutenant in the upper left arm, who returned fire but missed. The gunman shot through all the rounds of a 9 mm handgun before laying on the ground and surrendering to officers.

Both injured officers in the twin incidents were released from the hospital on Sunday and were greeted by claps and cheers from dozens of fellow officers waiting outside the hospital.

Mayor Bill de Blasio, who has come under harsh criticism from police officers in the past who accuse him of contributing to anti-cop rhetoric in the city, called the incidents "an attempt to assassinate police officers," and condemned the acts of violence.

"He's a cop killer," Lynch decried of Williams on Monday, before continuing to bash the "elected officials who rushed to the hospital," after the attacks but "aren't supporting us on a regular basis."

"It's not too late to stand up on that soapbox and say, 'My words against police officers did damage. My words got into the heads of criminals on the street who thought they were safe enough to try to kill police officers," Lynch said, taking aim at city officials like de Blasio.

Williams, a 45-year-old Bronx resident, has a criminal rap sheet and prior history of violence with police, investigators said. He was paroled in 2017 after an attempted murder conviction in 2002, when he shot a man and then carjacked a woman as he exchanged gunfire with New York City police officers.

Since his parole more than two years ago, he has one recorded arrest for which he was already scheduled to appear in court, Police Commissioner Dermot Shea told reporters on Sunday.

CLICK HERE FOR THE FOX NEWS APP

Williams was remanded into custody and is being held without bail.