LOS ANGELES — A police officer in Downey, about a dozen miles southeast of here, was shot and killed outside the city police department late Wednesday night in what law enforcement officials said was a “botched robbery attempt.”

The officer, Ricardo Galvez, 29, was sitting in his personal car in the Downey Police Department parking lot after a canine training session when two men ran up to the vehicle and shot him, said Lt. John Corina of the Los Angeles Sheriff’s Department.

Earlier on Thursday, officials at the sheriff’s department had said they believed that Officer Galvez had been targeted. But later in the day, three suspects detained in connection with the killing said they had been trying to rob him, Lieutenant Corina said.

Officer Galvez was in plain clothes at the time, and the assailants did not realize that he was a police officer, Lieutenant Corina said; the parking lot was accessible to the public.