The illegal immigrant killed Sunday in a shootout with a California cop had been deported three times and arrested and released over ICE's objection on several occasions -- including cases involving the very department whose officer took him down in a dramatic exchange caught on her body cam.

In a graphic, 48-second clip released Wednesday, body camera footage from Sunday's traffic stop shows Javier Hernandez Morales rolling down his window, grabbing a handgun and opening fire. Napa County sheriff’s Deputy Riley Jarecki narrowly avoided getting struck before running to the other side of the car, firing at least 15 shots into the red Honda.

Hernandez Morales, 48, died at the scene and the deputy was not seriously injured, officials said.

A second weapon – a loaded .22-caliber rifle – was found in the backseat of the Honda in addition to the pistol.

CALIFORNIA SHERIFF RELEASES GRAPHIC VIDEO OF DEADLY POLICE SHOOTING

Immigration officials said Thursday that the shooting and the man’s death could have been prevented, but California’s state law prohibited them from arresting the Mexican citizen with a long rap sheet and multiple deportations.

Immigration and Customs Enforcement said Hernandez Morales has been deported three times before 2011 – twice in 2007 and once again in 2010.

Since then, ICE had issued four separate detainers for him related to various arrests including suspicion of driving under the influence, battery on a peace officer and unknown probation violations.

ICE said detainers were issued to Napa County Jail in 2014, 2015 and 2016 while Sonoma County Jail received one in 2016. None of the detainers were honored by jail staff.

“This incident may have been prevented if ICE had been notified about any of the multiple times Hernandez-Morales was released from local custody over the last few years,” immigration officials said. “This is an impactful, scary example of how public safety is affected by laws or policies limiting local law enforcement agencies’ abilities to cooperate with ICE.”

MAN CLAIMING APPOINTMENT WITH TRUMP STRIKES SECRET SERVICE OFFICER OUTSIDE WHITE HOUSE, AUTHORITIES SAY

The statement added: “ICE is grateful the deputy involved in this shooting was not harmed during this attack. It’s unfortunate that our law enforcement partners and the community are subjected to dangerous consequences because of inflexible state laws that protect criminal aliens.”

California’s sanctuary law – signed by Gov. Jerry Brown in 2017 – largely prohibits local enforcement from keeping illegal immigrants in custody at the request of federal immigration officials.

Napa County supervisors told ABC 7, which broke the news, that the county has been following state law since 2017.

“Compliance with state law is what Napa County will, in fact, follow through upon, whether there are changes in the future that change things but as of right now we do need to comply with state law and that is what our policy reflects,” Napa County Supervisor Belia Ramos told ABC 7.

Henry Wofford, a sheriff’s spokesman, told the San Francisco Chronicle that the department was alerted by immigration officials to Hernandez Morales’ status prior to ICE issuing a press release on Thursday.

“We’re not talking about that information because that’s an ICE issue,” he said. “We know our role has always been sticking with the role in the community.”

CLICK HERE TO GET THE FOX NEWS APP

Officials said Hernandez Morales worked as a farm laborer in the area and had prior arrests for DUI, resisting arrests and possession of a firearm. There was a warrant for his arrest at the time of the shooting.

The sheriff’s department said Jarecki, who has been placed on administrative leave, was sworn in as a Napa County deputy six months ago, and her father is a sergeant in the department. Her grandfather also served with the Napa Police Department.