It was not immediately clear whether Mr. Castaneda had a lawyer. He was expected to be arraigned on Friday, Lieutenant Whitney said.

Lieutenant Whitney said the crimes began around 4 p.m. Wednesday when a burglary was reported at an apartment complex in Garden Grove, a city of 175,000 people next to Santa Ana in Orange County. He said the attacker lived in the apartment complex.

Twenty minutes later, the police received a report of a robbery at a nearby bakery. At about 5 p.m., the police found two men with multiple stab wounds back at the apartment complex — the same people who had initially reported the burglary. One was pronounced dead at the scene, while another died from his wounds at a nearby hospital, Lieutenant Whitney said.

At about 5:40 p.m., a robbery was reported at a check cashing business in Garden Grove. Shortly after 6 p.m., another robbery was reported at an insurance business, where an employee had been stabbed multiple times. She is expected to survive, Lieutenant Whitney said.

“She fought as best she could against this suspect,” he said.

Shortly afterward, at a nearby Chevron gas station, the attacker confronted a man pumping gas and stabbed him multiple times, the police said.

The man, who was not robbed, was taken to a nearby hospital and was expected to survive, Lieutenant Whitney said. He said the man’s nose was nearly severed off his face.

The police then found the suspect’s car, a silver Mercedes, at the 7-Eleven. The man disarmed and fatally stabbed a security guard who happened to be shopping at the store, taking the guard’s gun. As the suspect walked out, he was confronted by police officers, who arrested him without incident.