An illegal immigrant who allegedly shot a deputy before leading investigators on a high-speed chase was roaming free thanks to California’s sanctuary city policies, a local sheriff claims.

Guadalupe Lopez-Herrara, 51, was being sought by Merced County sheriff’s deputies for allegedly violating a restraining order, according to Fox 26 TV.

As deputies approached the home where Lopez-Herrara was working, they allege that he shot one of them in the vest and leg while hiding in some shrubbery.

The deputy is expected to recover from his injuries.

Authorities say Lopez-Herrara escaped and then carjacked a truck.

Guadalupe Lopez-Herrara, 51, was taken into custody by Merced County sheriff's deputies on Thursday

Lopez-Herrara allegedly shot a deputy on Wednesday as they sought his arrest for violating a restraining order

Authorities say Lopez-Herrara has a history of violent crime which includes arrests for spousal abuse and assault with a deadly weapon

The next day, police in Paso Robles spotted the stolen truck based on its make and license plate number.

As deputies gave chase, Lopez-Herrara allegedly reached speeds of more than 120 miles per hour.

As officers gave chase on Highways 46 and 41, other drivers pulled over to the side of the road in order to assist.

Finally, an officer used a spike strip to puncture the truck’s tires. Lopez-Herrara kept driving until he reached Interstate 5 near Harris Ranch.

Authorities say Lopez-Herrara stole a truck (right) and then led police on a high-speed chase

Merced County Sheriff Van Warnke (above) blasted California's sanctuary city laws, saying they enabled Lopez-Herrara to continue to commit violent crime

Authorities say that Lopez-Herrara kept firing at the deputies through the windshield of the truck after he came to a stop.

Lopez-Herrara has a criminal record which includes arrests for violent crime, including assault with a deadly weapon, felony assault, spousal abuse, possessing narcotics, and violating probation.

Merced Sheriff Van Warnke says that California’s sanctuary city laws, which bar local law enforcement from cooperating with Immigration and Customs Enforcement, enabled Lopez-Herrara to continue to commit crimes despite his record.

‘This person is not a legal citizen within the United States,’ the sheriff said.

‘We had him in our custody in January of this year.

‘And because of the folks in Sacramento limiting our ability to cooperate with ICE, we could not turn him over.’

Warnke added: ‘Bottom line is our immigration policies need to be revamped because we're gonna continue to have more of this situation happen...We knew ahead of time this guy's potential for violence was there.’