An off-duty city Department of Correction officer was shot and injured Sunday night while trying to stop a shooting in Queens, police said.

According to officials, a 23-year-old, who was awaiting sentencing for a firearm-related crime, pointed his gun into a crowd of people celebrating the holiday weekend at 214th Place and Jamaica Avenue around 8 p.m. They said the officer, David Donegan, who happened to be nearby, fired his own weapon. Both were shot.

Mayor Eric Adams called it a “perfect example of a failing criminal justice system.”

“Those who were arrested for having firearms, we need them off our streets as we enter the summer months,” he said. “Let’s sentence them. Let’s prosecute them. Let’s make sure that they’re not able to come back on our streets.”

Police said both Donegan and the 23-year-old went to the hospital with non-life threatening injuries. Another man also came to the hospital with gunshot injuries, though officials did not initially know what his involvement was in the incident.

"Our officer used his law enforcement training to protect the lives of people in the community," a DOC spokesperson said in a statement Monday. "These heroic actions make us all proud of the work we do every day."

The circumstances surrounding the shooting were still unclear as the investigators reviewed video evidence and canvased the scene for witnesses. Officials provided some preliminary information at a press conference after the shooting, but neither the New York Police Department nor the Department of Correction have offered further details to Gothamist. It is unclear how many people fired weapons, or who pulled the trigger first.

When asked by a reporter whether officers are trained to shoot a gunman if they are surrounded by a crowd, NYPD Chief of Patrol Jeffrey Maddrey did not directly answer the question. But he praised the officer’s actions.

“The primary goal of law enforcement is to protect lives,” he said. “The off-duty correction officer saw a threat and took action to stop that threat.”

Benny Boscio, president of the Correction Officers' Benevolent Association, described the officer's actions as "nothing short of heroic."

“Yesterday evening, as a crowd of people were observing an event remembering the passing of a friend, two individuals pulled out weapons and pointed them, firing at the crowd including our correction officer, David Donegan," he said in a statement. "Thankfully, officer Donegan, who was off duty at the time, immediately pulled out his weapon and engaged them, firing several shots. During the exchange of shots fired, our officer was hit in the leg and transferred to a nearby hospital. While the police investigation remains ongoing, one thing is crystal clear, had our officer not exercised his training and made a split second decision, this incident could have cost many innocent people their lives, including his own."

The shooting comes just days after New York lawmakers passed legislation to make it illegal to carry a gun in many parts of the city where large groups gather, including the subways, concert venues and Times Square. A Supreme Court ruling overturned the state’s prior concealed carry law, which was one of the strictest in the country. That decision heightened fears about a potential increase in gun violence with more firearms on the streets, especially as the city enters into the summer months, when gun violence tends to climb.

Police data show that shootings are down compared to this time last year, though they are still above pre-pandemic lows. According the NYPD, 31 people had been shot over the holiday weekend as of Monday morning.

This story has been updated with additional comment and information.