The man arrested and charged with the killing of a 31-year-old woman on San Francisco’s Pier 14 last week had been deported five times and had a more than 20-year history of run-ins with the law — including just months before the latest incident that landed him in jail.

So what was he doing on the streets of San Francisco?

Federal immigration officials say that the practices that have made San Francisco a “sanctuary city” allowed this “preventable” crime to happen.

“If the local authorities had merely NOTIFIED [U.S. Immigration and Customs Enforcement] that they were about to release this individual into the community, ICE could have taken custody of him and had him removed from the country — thus preventing this terrible tragedy,” ICE spokeswoman Gillian Christensen said in a statement.

On July 1, Kate Steinle, 31, was walking along Pier 14, taking pictures with her father around 6:30 p.m. when a shot rang out, fatally wounding her in the chest.

Not long after, police arrested Juan Francisco Lopez-Sanchez, 45, and charged him with the killing.

In March, Lopez-Sanchez had been released from federal custody and handed over to local authorities so that he could face drug charges. Those charges were later dropped and he was released from San Francisco County Jail on April 15.

Before Lopez-Sanchez was released, ICE officials filed an “immigration detainer,” which requests that local authorities notify federal officials before they released him from jail.

But in keeping with its long-standing policy, the San Francisco Sheriff’s Department ignored that request.

In a statement, the San Francisco Sheriff’s Department said that when Lopez-Sanchez was booked in jail, there was no “active ICE warrant or judicial order of removal for him.” Law enforcement in San Francisco will only release an individual into ICE custody if there is a warrant or court order for his deportation.

In this case, according to ICE, that policy had fatal results.

“As a result, an individual with a lengthy criminal history, who is now the suspect in a tragic murder case, was released onto the street rather than being turned over to ICE for deportation,” Christensen said. “ICE places detainers on aliens arrested on criminal charges to ensure dangerous criminals are not released from prisons or jails into our communities.”

“We’re not asking local law enforcement to do our job … all we’re asking is that they notify us when a serious foreign national criminal offender is being released to the street so we can arrange to take custody,” she added.

This public tug of war between local and state officials — especially in California– isn’t new.

The city has been designated a “sanctuary city” since 1989 — which is, legally, a meaningless distinction. But it is one that has frustrated federal officials in practice.

For years, the city has refused to cooperate with federal immigration raids. On one such occasion in 2007, then-San Francisco Mayor Gavin Newsom made it clear that the city would continue to resist efforts to enforce immigration law within its borders.

“I will not allow any of my department heads or anyone associated with this city to cooperate in any way shape or form with these raids,” Newsom said according to SFGate. “We are a sanctuary city, make no mistake about it.”

More recently, in November 2014, the Department of Homeland Security changed its policy on immigration detainers. Instead of requesting that local officials hold prisoners longer so they could be held for immigration violations — a practice that had been successfully challenged in the courts — federal officials now ask to simply be notified.

Even that change didn’t soften San Francisco’s opposition.

As a matter of policy, San Francisco limits its communication with ICE officials and flat out ignores immigration detention orders, city and county officials reiterated earlier this year.

According to the Obama administration, immigration enforcement actions have shifted away from low-level offenders to serious threats to public safety.

Lopez-Sanchez, they said, was justifiably a target for enforcement.

The Mexican national has been in and out of jail since 1991 on charges including heroin possession, felony manufacturing narcotics, and illegally re-entering the United States.

In an interview with local station KGO, Lopez-Sanchez said that he continued to enter the United States from Mexico while “looking for jobs in the restaurant or roofing, landscaping, or construction.”

He added that he picked up the gun, which he said was wrapped in a T-shirt, and it fired accidentally.

Not realizing that he had shot someone, he kicked the gun in the water and walked away, Lopez-Sanchez said.

Meanwhile, Steinle’s family is grieving for a life taken too soon.

“Days ago the most loving, beautiful, and amazing person was taken from us … my best friend, my love, my sister,” Steinle’s brother Brad Steinle said on the family’s GoFundMe page. “Kate had a special soul, a kind and giving heart, the most contagious laugh I have ever heard and smile I have ever seen.”