The San Bernardino County District Attorney's Office said Kenneth Paul Munoz Jr. fought with a deputy who was trying to handcuff him and then pulled the gun out of his holster in the Oct. 26, 2011, incident.
"In such circumstances officers are entitled to use deadly force in protection of themselves or others," prosecutors wrote in a report.
Sheriff's deputies encountered Munoz in the 35000 block of Avenue B in Yucaipa after receiving a report that he had a company car that he refused to return.
He jumped over a fence into a neighbor's backyard and climbed up a tree, authorities said.
Deputies found him about 30 minutes later and reportedly ordered him to lie on the ground until more deputies arrived.
He complied, but then got on his knees and began punching a deputy who tried to handcuff him, authorities said.
Munoz reportedly grabbed the deputy's gun.
"The two struggled for the weapon and it discharged. No one was hit," prosecutors wrote.
Eventually the deputy who was struggling with Munoz broke away, but other deputies on scene didn't know who had the gun because it was dark, authorities said.
Sheriff's Sgt. Michael O'Brien and Deputy Ismael Diaz opened fire on Munoz, striking him 12 times.
Coroner's officials said Munoz had a number of drugs in his system, including methamphetamine, hydrocodone and opiates.
Reach Melissa via email or call her at 909-386-3878.
Get the latest crime and public safety news on Twitter @IECrime.