JUBA, May 5 (Reuters) - South Sudan's outgoing army chief General James Hoth Mai accused neighbour and old foe Sudan on Monday of arming rebels fighting his troops in an increasingly ethnic conflict - allegations quickly dismissed by Khartoum.

Thousands of civilians have been killed during more than four months of fighting which the United States and regional powers warn could spiral into full-blown genocide if left unchecked.

Mai told Reuters it was an "open secret" that the Khartoum government was backing insurgent leader Riek Machar in a bid to destabilise South Sudan, which seceded from Sudan in 2011 after decades of north-south war.

"Khartoum has been helping (Machar's) militia all along," Mai said at his residence opposite the presidential palace in the South Sudanese capital Juba.

Sudanese authorities denied having any link to the rebels.

"We cooperate with the South Sudanese government as the only legitimate government and we don't deal with the rebels," Sudanese army spokesman Al-Sawarmi Khalid told Reuters.

The conflict started with fighting between rival groups of soldiers in Juba mid December and quickly spread across the country.

It is widely seen as the result of a long-running political rivalry between President Salva Kiir and his sacked deputy, Machar, exacerbated by tensions between their ethnic groups - Kiir's Dinka people and Machar's Nuer.

Most senior South Sudanese figures have up to now not implicated Khartoum or any other external player.

But Sudan and South Sudan have regularly accused each other of supporting rebels in each other territories in past conflicts to fight proxy battles over territory and oil rights. Mutual distrust remains deep.

Mai - who is due to step down this week after Kiir gave him his notice last month - said Machar's rebels had amassed troops inside Sudan before crossing the border and attacking the northern oil town of Bentiu in April.

No official explanation was given for Mai's dismissal, but analysts said it could have been due to the fact he was a Nuer, or because the fight against the rebels had suffered setbacks.

"(The rebels) have a safe haven in the north and get supplied there," said Mai.

He said three trucks full of ammunition, food and other supplies were captured in Bentiu in January when SPLA government troops first routed the rebels there. Mai showed no evidence to prove Sudan had provided the materials.

Unmarked planes had also dropped supplies to rebel camps, but it was hard to identify who was behind this, he added.

HISTORY OF BLAME

Machar was not immediately available for comment.

One senior Western diplomat told Reuters late last month he thoughy Bashir was playing both sides in the South Sudan conflict, trying to sow chaos and show that South Sudan could not manage itself.

"Khartoum is giving weapons to Machar while publicly denying any support. At the same time (Bashir) is trying to appease Kiir. There are fighters supported by Bashir in South Sudan," said the diplomat.

"Khartoum has never accepted the independence of the south."

Other diplomats, however, say there is scant evidence of Khartoum directly arming rebels. They say South Sudan's army has a history of blaming Bashir to cover up its own failings.

South Sudan's army battled rebels in and around Bentiu on Monday, hitting hopes for renewed peace efforts days after U.S. Secretary of State John Kerry visited to try and revive faltering peace talks.

Both sides have been accused of atrocities.

Mai acknowledged SPLA soldiers were involved in the "killing of innocent people in Juba" early in the conflict, but said rebel massacres outweighed any crimes committed by his men.

Mai, 54, regarded as the most prominent Nuer and an emblem of Dinka-Nuer cooperation, told Reuters his dismissal came as a surprise. He will be replaced by Paul Malong, said by analysts to be a Kiir loyalist and Dinka hardliner. (Additional reporting by Khaled Abdel Aziz in Khartoum; Editing by Richard Lough and Andrew Heavens)

We welcome comments that advance the story through relevant opinion, anecdotes, links and data. If you see a comment that you believe is irrelevant or inappropriate, you can flag it to our editors by using the report abuse links. Views expressed in the comments do not represent those of the Thomson Reuters Foundation. For more information see our Acceptable Use Policy.