A deputy in South Carolina won't face criminal charges for killing a man who managed to get into his police car and grab a rifle, according to a prosecutor.

York County Deputy Gary Pence was struggling to see Trenton Fondren in the dark and trying to stay safely away from the knife he was carrying when Fondren managed to get into his patrol car through the open driver's door on Dec. 1, Solicitor Kevin Brackett said.

Pence had already warned that he was going to shoot if Fondren didn't drop the knife when the man grabbed a rifle that was between the seats of the patrol car, Brackett said.

"He had only seconds to react and decide how to respond and was forced to make his decisions in very limited visibility. Despite his best efforts to buy time to talk by retreating, Deputy Pence was placed in an untenable position," Brackett said in a letter to the State Law Enforcement Division.

Pence was responding to a call about a man with a knife walking along a road at 4 a.m. He was the only officer in the area, Brackett told media outlets. He was not hurt.

Toxicology tests showed Pence was intoxicated when he was killed, and his mother reported he had threatened her with the knife before the deputy arrived, Brackett said.