Seven South Carolina law enforcement officers were shot — one fatally — during a standoff with a man holding children hostage in his home Wednesday.

Three sheriff’s officers initially were struck during the two-hour standoff, which began when they knocked on the front door of a home in an attempt to execute a search warrant at about 4 p.m., according to Florence Police Chief Allen Heidler, who didn’t reveal details of the warrant.

“These officers went there unknowing the firepower that this suspect had,” Sheriff Kenneth Boone said, adding that the suspect was in custody.

“They thought it was a random search warrant. But when they arrived, gunfire started and several officers were hit.”

The suspect then barricaded himself inside the residence with the children.

Arriving officers from the Florence Police Department were met with more gunfire, and four were struck.

“Fire was being shot all over,” Boone said.

“The way the suspect was positioned, his view of fire was several hundred yards. So he had an advantage and the officers couldn’t get to the ones that were down.”

One officer died, while a bulletproof armored vehicle drove up to rescue the survivors.

Officials later identified the slain officer as Terrence Carraway — who had just celebrated 30 years with the Police Department.

“I want you to pray for the family who lost the bravest police officer I have ever known,” Heidler said.

Cops said a 20-year-old civilian inside the home was also shot, but it wasn’t immediately clear if he was the suspect or someone else in the home.

Officials did not reveal the suspect’s name.

South Carolina Gov. Henry McMaster tweeted his prayers and condolences.

“This is simply devastating news from Florence,” McMaster wrote.

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

President Trump also tweeted his condolences.

“My thoughts and prayers are with the Florence County Sheriff’s Office and the Florence Police Department tonight, in South Carolina. We are forever grateful for what our Law Enforcement Officers do 24/7/365,” he wrote.

The number of children caught in the standoff or their conditions weren’t immediately revealed.

Florence, a city of 37,000 people, was affected by Hurricane Florence last month, but did not bear the brunt of the storm, which devastated other areas.

With wires