Deputies shot and killed a man who opened fire on them during a traffic stop in South Carolina, authorities said.

Charleston County Deputy Evan Cubbage was hit three times by gunfire and was treated at a hospital and released, Sheriff Kristin Graziano said at a news conference.

Cubbage pulled over a vehicle about 3:45 p.m. Sunday on U.S. Highway 17 near Ravenel, the sheriff said.

After briefly talking to the driver and passenger, Cubbage called for backup, and when the second deputy arrived, the passenger started shooting at them, Graziano said.

Both deputies fired back and James Rakeem Pierce, 28, was killed, authorities said.

SOUTH CAROLINA GROOM PLANNING BRIDE'S FUNERAL AFTER TRAGIC WEDDING DAY CRASH

South Craolina Fox News graphic

South Carolina deputies  a fatallyshot a man who opened fire at them during a traffic stop.

CLICK HERE TO GET THE FOX NEWS APP

Graziano didn't know what prompted the traffic stop.

"We were very, very, very lucky today that these two deputies survived this incident," the sheriff said.

Cubbage spent about six hours in the hospital before he was released, authorities said.

The woman driving the car was detained. The State Law Enforcement Division, which is investigating, has not said whether she will face charges.

The traffic stop took place on a rural part of U.S. 17 about 15 miles west of Charleston.