The gunman, 26-year-old Mason Lira, was stopped in the vicinity of Paso Robles, where investigators said he shot a deputy in the head Wednesday.
The district attorney of San Luis Obispo County tweeted that four law enforcement officers had been shot in all. Investigators said Lira was in custody, "secured and unresponsive," and later confirmed his death.
The three officers wounded Thursday were expected to recover, investigators said.
The shootout capped off a manhunt that had stretched over 24 hours, involving hundreds of police officers. Officials closed parts of a freeway and used flash-bangs while searching apartments.
Tony Cipolla, a spokesman for the San Luis Obispo County sheriff, described the search as "a wide-ranging, full-on, full-scale effort."
A gas station clerk reported seeing Lira around 2 a.m. Thursday when he came in to buy an energy drink, KSBY reported. The clerk said Lira was sweaty, exhausted and mumbling to himself but did not do anything threatening.
The suspect's father, Jose Lira, told The Associated Press that his son had mental illnesses and refused to take medication but had no particular animus toward law enforcement. He said his son often thought he was a special agent or a solider and may have believed he was under attack or in a war zone.
Although investigators have described the attack on the Paso Robles police station as an ambush, his father said he thought it might have been a suicide attempt.
Jose Lira said he last spoke to his son about two months ago, when he was threatened by him and became belligerent.
"I slept with a gun loaded under my pillow last night," he said. "I'm afraid of him, too."
Jose Lira said his son has been homeless since he was 17, in and out of jails and mental health facilities.
"He doesn't trust anybody, he's always by himself," he said.
Jose Lira first spoke to The Visalia Times-Delta.
The events started unfolding around before dawn Wednesday, when Lira allegedly fired at police cars as they entered downtown Paso Robles.
Two sheriff's deputies said they heard gunshots but didn't see the attacker until they were outside their patrol car and gunfire targeted them. One was hit in the head. His partner fired back and dragged the deputy behind a police car. The wounded deputy, Nicholas Dreyfus, 28, had a good prognosis Thursday after surgery.
While officers searched for Lira, they received a report of a body near a train station and found a 58-year-old man shot to death on the tracks. He appeared to be a transient who was camping out overnight. It wasn't immediately clear when he was shot.
The attack came just five days after law enforcement officers were ambushed farther north in the community of Ben Lomond. There was no indication the shootings were related.
Santa Cruz County sheriff's Sgt. Damon Gutzwiller, 38, was killed and another deputy injured Saturday in an attack by an Air Force sergeant armed with homemade bombs, an AR-15 rifle and other weapons, investigators said. Sheriff Jim Hart said the suspect, Steven Carrillo, was intent on killing officers.
Carrillo, 32, was arrested and the FBI was investigating whether he had links to the killing of a federal security officer outside the U.S. courthouse in Oakland during a protest against police brutality on May 29. A white van was spotted at both attacks.
In Paso Robles, there were no events that could have triggered the violence, San Luis Obispo County Sheriff Ian Parkinson said. Investigators said they didn't know if the attack was connected to anger over the killing of George Floyd by Minneapolis officers, he said.
Jose Lira said he doubted his son had any connection to the Santa Cruz and Oakland killings since he preferred to be alone.
"He lives in a fantasy world," Jose said. "He doesn't have a beef with the police."
The Associated Press contributed to this report.