Federal immigration officials said Thursday that California law had prohibited them from arresting a Mexican citizen with a record of deportations and probation violations before he was shot to death Sunday by a Napa sheriff’s deputy during a traffic stop — and that the shooting might never have happened if they had been allowed to detain him.

In a graphic 48-second clip released Wednesday, body-worn camera footage shows the shooting as it unfolded after Napa County sheriff’s Deputy Riley Jarecki stopped to conduct a vehicle check of a red Honda parked in a southern part of Napa County around 11 p.m.

After Jarecki’s brief conversation with Javier Hernandez-Morales, 43, who was seated in the driver’s seat, the video appears to show him rolling down the car window — and then firing at least one shot at Jarecki with what police say was a stolen .22-caliber revolver at point-blank range. The deputy ran around to the other side of the car and fired at least 15 shots into the Honda.

Hernandez-Morales, an undocumented immigrant, died at the scene, officials said, and the deputy was not seriously injured.

Detectives found a second firearm, a loaded .22-caliber rifle, in the car, according to the Napa County Sheriff’s Office.

Officials with Immigration and Customs Enforcement said Thursday that the shooting and his death could have been prevented.

State law largely prohibits local law enforcement from cooperating with federal immigration officials, keeping undocumented immigrants in custody at the request of federal immigration officials, or asking people who are under arrest about their immigration status. California’s sanctuary law was signed by Gov. Jerry Brown in 2017 and took effect in 2018.

Hernandez-Morales, who lived in Napa, had been deported three times before 2011: twice in 2007 and once in 2010. Since 2011, ICE had issued four separate detainers for him related to arrests on suspicion of driving under the influence, battery on a peace officer, selling liquor to a minor and unknown probation violations, ICE officials said in a statement to The Chronicle.

None of the detainers — which were issued to the Napa and Sonoma county jails — was honored by jail staff, ICE officials said. Specific details of arrests and violations were not immediately available.

“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 in a statement. “This is an impactful, scary example of how public safety is affected by laws or policies limiting local law enforcement agencies’ ability to cooperate with ICE.”

A detainer or “immigration hold” is a written request by ICE to a local jail or law enforcement agency to detain an undocumented immigrant arrested on criminal charges for an additional 48 hours after his or her release. The intent is to give ICE time to arrest the individual and begin deportation proceedings.

Detainers have been the focus of intense debate for several years, often sparking questions about whether local law enforcement agencies should cooperate with authorities to enforce immigration law. Advocacy groups such as the ACLU argue that the practice allows ICE to detain people without due process, often without any pending charges.

Henry Wofford, a sheriff’s spokesman, told The Chronicle that his department was alerted by federal immigration officials to Hernandez-Morales’ status just prior to ICE issuing a press release about the issue on Thursday.

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

Immigration officials wrote in their press release they were “grateful” that Deputy Jarecki was not physically harmed during the shooting.

“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,” ICE officials wrote.

However, immigration advocates say individual tragic events such as Sunday’s shouldn’t be used to demonize entire groups of people.

“We have seen how ICE and the president politicize tragedy, and I think that is irresponsible and wrong,” said Jon Rodney, spokesman for the California Immigration Policy Center.

Rodney said the state’s sanctuary law helps crime victims and witnesses come forward without fear of being turned over to ICE.

ICE officials said they issued three detainers for Hernandez-Morales to Napa County Jail in 2014, 2015 and 2016. They issued an additional detainer for him to Sonoma County Jail in 2016.

Napa County Undersheriff Jon Crawford said in a Wednesday afternoon news conference that he believes Hernandez-Morales intended to kill Jarecki when he pulled out the pistol and fired at her. Investigators have not determined a motive in the shooting.

The incident is being investigated by the Napa County Major Crimes Task Force, a panel that includes the Sheriff’s Office, the Napa Police Department and the Napa County district attorney’s office.

Sonoma County sheriff’s officials could not be immediately reached for comment.

San Francisco Chronicle staff writer Tatiana Sanchez contributed to this report.

Lauren Hernández is a San Francisco Chronicle staff writer. Email: lauren.hernandez@sfchronicle.com Twitter: @LaurenPorFavor