BAKERSFIELD, Calif. (KGET) — It’s an incredible story of survival and bravery, as a Kern County Sheriff’s Deputy was shot in the head this morning in Rosamond and survived.

Deputy Michael Valdez was shot in the head Friday morning. According to the Sheriff’s Office, this wasn’t a graze wound. The bullet cleanly entered and exited his skull but got stuck in his hat. The sheriff’s office says this is nothing less than a miracle and an act of God that Valdez is still alive.

Deputy Michael Valdez is a new hire with the Kern County Sheriff’s Office. He just wrapped up field training five weeks ago but now he already has combat experience.

Sheriff Donny Youngblood said it all started after 3:30 a.m. Friday in Rosamond. The suspect, 19-year-old Edgar Rojas, was allegedly trying to open car doors and set off multiple alarms at the Sierra Vista Mobile Home Park.

“Deputy Valdez saw the suspect, engaged him,” Kern County Sheriff Donny Youngblood said. “The suspect turned and ran.”

Deputy Valdez and his partner Deputy Danielle Henderson who’s been on the force for five years lost Rojas but they continued searching. They found him about half a mile north in an alley on Locust Street but that’s when the shooting happened, injuring Deputy Valdez and nearly taking his life.

“The report we got this morning, we have a deputy shot in the head, which is, you know, pretty traumatic,” Youngblood said. “Thank God it turned out the way it did.”

“This round actually went in here and circled the head and exited the rear. And the round was actually recovered from the hat he was wearing,” Youngblood said. “We’re talking a quarter inch from tragedy.”

Deputy Valdez was taken to Antelope Valley Hospital, treated with stitches and was released. Sheriff Youngblood says for now, Deputy Valdez says all he has is a headache.

17’s cameras were rolling on scene when multiple KCSO SWAT vehicles and officers came onto the scene. Just a bit later Rojas was detained at 7:30 in the morning. Deputies say he was using a 9mm ghost gun.

“Well, it’s a dangerous job we do. When you get shot, you don’t know how bad it is,” Youngblood said. “He stayed in the fight, continued to protect the community until the perimeter was established, and once help got there, he relieved himself of duty and they took over.”

Edgar Rojas has been booked on various charges including attempted murder and assault with a firearm on a peace officer, He’s due in court on Tuesday.