The US secretary of state, John Kerry, has warned of a possible genocide in South Sudan, and raised the threat of sanctions against the leaders of warring factions in the world's newest country.

"Those who are responsible for targeted killings based on ethnicity or nationality have to be brought to justice, and we are actively considering sanctions against those who commit human rights violations and obstruct humanitarian assistance," Kerry said in Ethiopia on Thursday at the start of six-day tour of Africa.

South Sudan gained independence from Sudan in 2011, but fighting broke out last December between the supporters of President Salva Kiir and those of former vice-president Riek Machar. Since then, thousands of people have died, many in ethnically targeted massacres.

Kerry's comments came after the UN commissioner for human rights, Navi Pillay, said that more than 9,000 child soldiers have been forced to fight in South Sudan's civil war. Pillay launched a blistering attack on Kiir and Machar for their apparent lack of concern about the looming threat of famine as the four-month-old conflict raged on.

"Unicef reports that more than 9,000 children have been recruited into armed forces by both sides," Pillay told a press conference in the capital, Juba, on Wednesday. "Thirty schools have been taken over by military forces and there have been more than 20 attacks on clinics and health centres.

"Many women and girls have been raped, often brutally and sometimes by several fighters. Others have been abducted. Children have also been killed during indiscriminate attacks on civilians by both sides. How much worse does it have to get before those who can bring this conflict to an end – especially President Kiir and Dr Machar – decide to do so?"

Pillay's visit was prompted by a rebel attack on the oil hub of Bentiu that left hundreds dead.

"The deadly mix of recrimination, hate speech and revenge killings that has developed relentlessly over the past four-and-a-half months seems to be reaching boiling point, and I have been increasingly concerned that neither South Sudan's political leaders nor the international community at large seem to perceive quite how dangerous the situation now is," Pillay said.

"Unfortunately, virtually everything I have seen or heard on this mission has reinforced the view that the country's leaders, instead of seizing their chance to steer their impoverished and war-battered young nation to stability and greater prosperity, have instead embarked on a personal power struggle that has brought their people to the verge of catastrophe."

The UN's top human rights official said she had also been sent to investigate recent killings in Bor, where residents in the predominantly ethnically Dinka town attacked a UN base where Nuer people were sheltering. Dozens were killed.

Pillay, who met Kiir in Juba and Machar at his base in the bush in Upper Nile state during her visit, said the two attacks "have starkly underlined how close South Sudan is to calamity".

The fighting has caused at least 1.2 million people to flee their homes during the crucial planting season, raising the prospect of mass hunger that could kill more people than the violence itself. Pillay said: "I was appalled by the apparent lack of concern about the risk of famine displayed by both leaders, when I raised the issue. The reaction to a call for 30 days of tranquillity to allow people to go home to plant – although it may already be too late for this with the rains starting – was lukewarm: both leaders said they would if the other did, then made it clear they did not trust the other's words.

"The prospect of widespread hunger and malnutrition being inflicted on hundreds of thousands of their people, because of their personal failure to resolve their differences peacefully, did not appear to concern them very much."

She added: "If famine does take hold later in the year, and the humanitarian agencies are deeply fearful that it will, responsibility for it will lie squarely with the country's leaders, who agreed to a cessation of hostilities in January and then failed to observe it themselves."

Last week the UN children's agency Unicef said nearly 250,000 children in South Sudan would suffer severe acute malnutrition this year if more was not done now. It said 50,000 children under the age of five were likely to die.

The World Food Programme says it faces a $224m (£130m) shortfall of an emergency request made to feed 1.1 million people. A donors conference is set for 20 May.