Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A South Carolina law enforcement officer was killed and six others were injured Wednesday when a man opened fire as they tried to serve a search warrant on him regarding a sexual assault investigation, officials said.

Terrence Carraway, 52, a 30-year veteran of the Florence Police Department, was killed in the shooting outside Florence, South Carolina.

Officers arrested the alleged gunman, Fred Hopkins, whose adult son was wounded by the gunfire. Authorities did not release their names, and it was unclear who shot the son, said Chief Deputy Glen Kirby of the Florence County Sheriff's Office.

A team from the sheriff's office, including two sex crime investigators, went to a residence about 4 p.m. to serve a search warrant regarding a sexual assault investigation, Kirby said.

A deputy who knocked on the front door was allegedly shot by Hopkins, 74, with what was described by Kirby as a high-powered rifle, he said.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

Florence County Sheriff Kenney Boone said three of his deputies and four police officers from the local police department were struck by the gunman.

Terrence Carraway, who was killed in the shooting. Terrence Carraway via Facebook

"His view of fire was several hundred yards, so he had an advantage," the sheriff told reporters at a nighttime news conference outside McLeod Regional Medical Center, where some of the injured were being treated.

Officers used extreme caution because they believed four foster children, roughly ages 10 through 17, were hiding inside the residence, Kirby said.

Hopkins, a disbarred lawyer, surrendered after a two-hour standoff, walking out of the house wearing a knee brace. He wasn't shot but was described as being unconscious, possibly because he had a heart attack or some other physiological response to the shootout, Kirby said.

The children were discovered unharmed and hiding under a golf cart in the garage, Kirby said.

Two of the three injured deputies were said to be in critical condition and the third, who was shot in the leg, was in stable condition, he said.

Of the three surviving police officers, one suffered a graze wound to his head and was paralyzed on one side, Kirby said. Another officer was in stable condition, and a third, shot in the thumb, was released from the hospital, Kirby said.

Florence police Chief Allen Heidler, who said he knew Carraway for 30 years, called it "a very horrific day in the annals of the Florence Police Department."

Late Wednesday, President Trump tweeted, "We are forever grateful for what our Law Enforcement Officers do 24/7/365."

Gov. Henry McMaster‏ called the attack "devastating news" for South Carolinians, and he asked for their prayers.

"The selfless acts of bravery from the men and women in law enforcement is real, just like the power of prayer is real," he tweeted.