A gunman with an AK-style assault rifle shot three cops in California on Wednesday — one fatally — as they tried to serve him with a search warrant, reports say.

The officers had been part of a Sacramento County Sheriff’s Auto Theft Task Force team, which was conducting a grand theft auto operation at a local Ramada Inn at around noon, according to KCRA.

They had just knocked on a suspect’s door and announced themselves when the man took out a “high-powered” rifle and began blasting, officials said.

A sheriff’s deputy and two California Highway Patrol officers wound up being hit, the deputy fatally.

At least three people were detained in connection to the shooting, officials said.

The suspects, described as a man and two women, were reportedly arrested in different areas.

Tactical teams were also searching for at least two others who were still holed up inside the Ramada Inn as of 3 p.m. local time.

The male suspect that was taken into custody had been staying at the hotel and was being surveilled by authorities in connection to the stolen car investigation. The females were about a half mile away and were also being watched by cops, KCRA reports.

At some point during the hotel operation, authorities went up to the man’s room and attempted to serve a search warrant — prompting him to open fire.

He shot the two CHP officers through the door and then went out the back of the Ramada Inn, where deputies were waiting. The suspect started blasting again — nailing Deputy Robert “Bob” French in his side — before getting into a Dodge Challenger and fleeing, officials said.

French, a 21-year veteran and grandfather, later died on his way to the hospital. The bullet that struck him was said to have traveled into his chest cavity.

“All agencies and departments lost a brother officer,” Sacramento County Sheriff Scott Jones said at a press conference. “We’ll survive this, we will, as a community, we’ll survive together. We’ve been through it before, but it is painful. It will take a period of grieving. And we will come together and through it with courage and resolve.”

The other two officers who were hit are expected to survive after being treated for non-life threatening injuries. One of them was slated to undergo surgery, officials said.

After fleeing in the Challenger, the male suspect reportedly crashed the car and then got into another shootout with police — but was hit this time by officers’ gunfire. The man’s condition is unknown.

Authorities initially took the two female suspects into custody after they spotted them getting into a stolen vehicle. They then went to the Ramada Inn to serve the male suspect with the search warrant, which was connected to the alleged auto theft.

“This is stuff we come in contact with every day, you know,” explained Sheriff’s Sgt. Tony Turnbull.

“It’s not war, but this is no different when you have instances like this,” he said. “We know with a lot of the narrative that’s going on these days that people have reason to shoot at us…Some of the reasons are that they don’t want to go back to jail or they don’t want to go back to prison. Officers on the streets are dealing with this every day. You just don’t know what’s going to happen, and especially in this incident, you don’t know what’s behind a closed door.”