A 14-year-old boy allegedly killed his father before going to a nearby primary school and opening fire injuring two pupils and a teacher.

Two six-year-old boys were hurt in the attack at Townville Elementary School in South Carolina on Wednesday.

One of the boys is in a critical condition and had to undergo surgery, officials said.

County coroner Greg Shore said the shooter had been arrested and taken into custody.

Authorities did not release a motive for the shooting and said they were not sure if the students and teacher were targeted.

Jamie Meredith, whose daughter goes to the school, said some of the children went into the toilets during the shooting.

"I don't know how they knew to go in the bathroom, but I know her teacher was shaken up. I know all the kids were scared.

"There was a bunch of kids crying. She didn't talk for about five minutes when I got her."

Armed officers were seen at the school, and NBC News reported they were taking children by bus from the school to a nearby church.

Governor Nikki Haley said: "As we work together with law enforcement to make sure they have the support they need to investigate what happened in Townville, I ask that everyone across South Carolina join us in praying for the entire Townville Elementary School family and those touched by today's tragedy."