A campus "peace officer" who sometimes worked alongside the NYPD was fatally shot by police on Tuesday, after allegedly ambushing two cops responding to a domestic violence complaint inside his home.

The shootout happened at 12:45 p.m. in the Springfield Gardens section of Queens, near JFK Airport. Police identified the gunman as Rondell Goppy, a 41-year-old crime prevention specialist, or "peace officer," at the City University of New York.

The two officers were with the woman who filed the domestic abuse complaint when Goppy stormed into the home and opened fire, according to police officials.

"Almost instantaneously he walks in the front door and starts shooting at our two officers," NYPD Commissioner Dermot Shea said during a press conference on Tuesday.

The officers returned fire, killing Goppy. He was pronounced dead at the scene.

Both officers were transported to Jamaica Hospital in stable condition, police said. One officer was shot in the thigh, and another struck "at least once in both hands," according to Shea.

After meeting with the two officers at the hospital, Mayor Bill de Blasio praised them for saving the life of the woman who reached out with the domestic violence complaint. "Because those officers were there, that women is alive," the mayor said. "God bless them."

Police said they recovered three hand handguns from the alleged shooter. According to Shea, he is a registered gun owner with no criminal history.

But a law enforcement official who spoke to the Associated Press said that Goppy had a history of domestic violence incidents, which led authorities to take his guns away last year, before later returning them.

The NYPD will investigate "why he was still in possession of those guns and what happened to those prior cases," Shea said.

Photos show Goppy preparing for an active shooter training in 2018 alongside uniformed NYPD officers, and speaking at a community outreach event hosted by the 105th Precinct.

Asked about the incident, a spokesperson for CUNY told Gothamist, "Right now we're not giving any comment," before hanging up.

This story has been updated.