BAKERSFIELD, Calif. (KGET) — The man accused of shooting a Kern County sheriff’s deputy in the head has been charged with attempted murder.

Edgar Rojas, 19, pleaded not guilty Tuesday to that charge and three other felonies: assault with a gun on a peace officer, resisting arrest and carrying an unregistered gun. He’s held on $650,000 bail and due back in court Dec. 16.

The deputy received stitches at a hospital and was released, an outcome the sheriff termed miraculous.

The shooting happened early Friday after deputies were called to the Sierra Vista Mobile Home Park in Rosamond to a report of someone trying to open car doors and setting off alarms, Sheriff Donny Youngblood said.

Deputies Michael Valdez and Danielle Henderson arrived. Valdez confronted Rojas, who fired a shot, and the deputy briefly lost sight of him, Youngblood said. Valdez again encountered the suspect, who fired four or five more rounds, one of which hit Valdez in the head, the sheriff said.

The bullet pierced Valdez’s skin, passed cleanly through and lodged in his hat, Youngblood said.

After being shot, Valdez returned to his vehicle, grabbed a shotgun and helped deputies and other arriving agencies set up a perimeter, Youngblood said. A sheriff’s SWAT team arrived and called the home where Rojas was believed to be hiding, demanding he surrender.

Rojas turned himself in and deputies recovered the gun used in the shooting, Youngblood said.