A California police officer was shot to death in his own car as he was getting off work in what investigators said Thursday was a botched robbery attempt by two young men and a 16-year-old boy who were arrested within hours.

Downey police Officer Ricardo "Ricky" Galvez, 29, was in plainclothes in the driver's seat of his car at the end of his shift when two men ran up and opened fire late Wednesday, Los Angeles County sheriff's Lt. John Corina said.

The former Marine, and five-year veteran of the department, died in his car.

Corina said the attackers — aged 21, 18 and 16 — were out looking for someone to rob when they spotted Galvez sitting in his car. Galvez was shot seconds later.

"They were attempting to rob Officer Galvez not realizing he was a police officer," Corina said. "I don't even think he saw these guys coming up on him."

Another officer heard the gunshots and pursued the attackers as they fled into the neighboring city of Montebello. Investigators said they arrested the getaway driver and other people were detained after SWAT officers swept surrounding neighborhoods.

Police also said they had recovered a gun they suspect was used to kill Galvez.

The three suspects were each booked on a charge of murder and expected to appear in court on Monday, Corina said. Prosecutors will decide later whether to charge the 16-year-old as an adult.

A young woman who identified herself as the sister of one of the suspects cried and yelled outside a news conference announcing the arrests that her brother didn't do it.

She was unavailable for questions after investigators took her inside to interview her.

Detectives knew quickly that Galvez had been shot in a deliberate, targeted attack.

"It appeared to be an ambush style. It happened very quickly," Corina said after viewing surveillance video of the shooting.

Corina said he wasn't immediately able to tell if words were exchanged before Galvez was shot.

Downey police Chief Carl Charles praised Galvez's professionalism and said the officer had an infectious smile and a great attitude.

"Words cannot express the love we have for Ricky," he said.

Galvez was a Marine veteran from the Downey area. He was single and lived close to his siblings and other family members, Charles said at a news conference.

Downey police Lt. Mark McDaniel said Galvez "loved serving the city and he loved serving his country."

"If you could mold a police officer, you would mold that police officer after Ricky Galvez," McDaniel said. "We have a lot of police officers here who are hurting. We'll never get over it and we'll always remember Ricky."

Dozens of officers wiped away tears and saluted as police carried Galvez's American flag-draped body from the crime scene to a coroner's van.

California Gov. Jerry Brown said flags will be flown at half-staff at the Capitol in Sacramento in honor of Galvez.

Downey is a city of about 110,000 residents 10 miles southeast of downtown Los Angeles.