* President blames supporters of sacked deputy
* Thousands take shelter at U.N. bases in capital
* South Sudan has struggled since 2011 independence
By Carl Odera
JUBA, Dec 16 (Reuters) - Gunfire rang out again in South Sudan's capital Juba late on Monday hours after President Salva Kiir said his forces had quelled an "attempted coup" by supporters of his sacked deputy.
Kiir earlier said fighters loyal to former vice president Riek Machar had attacked an army base into the early hours of Monday morning, but the military was in control. He imposed a dusk-to-dawn curfew.
After the streets emptied, and thousands of locals took refuge in U.N. compounds in Juba, diplomats and a U.N. official reported hearing fresh shooting from around 10 p.m. (1900 GMT) in the city's Tomping neighbourhood.
"We too have heard the gunshots in Tomping. Really urging everyone to stay indoors and stay safe," the U.S. embassy in Juba said on its Twitter feed. Mobile phone networks were down across the capital.
The U.N. official, who asked not to be named, told Reuters they had turned out the lights to avoid attracting attention.
The government has struggled to establish a functioning state since declaring independence from Sudan in 2011 to become Africa's newest nation.
Kiir dismissed Machar after mounting public criticism at the government's failure to deliver better public services in the oil-producing nation, which is the size of France but barely has any tarmac roads.
The two men are from different ethnic groups which have clashed in the past. Machar has said he wants to run for president.
Heavy gunfire and blasts first erupted late Sunday and into early morning, then appeared to die down by midday, as government soldiers patrolled the streets and set up roadblocks, said witnesses.
Kiir appeared on national television on Monday afternoon, flanked by ministers and wearing combat fatigues rather than his usual civilian clothes.
He said the fighting broke out after an unidentified person fired shots in the air near a ruling party conference.
"This was followed later by an attack at the SPLA (South Sudan army) headquarters near Juba University by a group of soldiers allied to the former vice-president Dr Riek Machar and his group. These attacks continued until this morning," he said.
"However, I would like to inform you, at the outset, that your government is in full control of the security situation in Juba."
At least 10,000 civilians took refuge in U.N. compounds in the capital, said one U.N. official who asked not to be named.
Kenyan airlines Fly540 and Kenya Airways suspended flights indefinitely to Juba after the airport closed.
Speaking by phone earlier in the day, a U.N. spokesman said seven people had been treated for gunshot wounds, including a two-year-old boy.
A Reuters reporter saw one man with blood all over his legs being carried by civilians along the largely deserted streets in the direction of the hospital.
The earlier clashes were concentrated at two military bases, the Bilpam barracks north of the airport and the Jebel barracks south of Juba, where the presidential guard is based, residents said.
The fighting is the latest setback for one of Africa's poorest states. Oil production, South Sudan's main source of revenue, was shut down for 15 months till April because of a row with Sudan, which hosts the main export oil pipeline.
"I urge all parties in the fighting to cease hostilities immediately and exercise restraint," U.N. Special Representative of the Secretary-General Hilde Johnson said.
Jok Madut Jok, chairman of South Sudan's Sudd Institute think tank, also said troops loyal to Machar were to blame.
"Riek Machar is not new to this kind of militaristic avenue to power," he said by telephone from Juba.
After accepting his dismissal at the time, Machar has since accused the president of acting like a dictator. Kiir said last week that some "comrades" were threatening to drag the nation back to a period in 1991 when South Sudanese ranks were split.
The fighting has revived memories of the factionalism in the 1990s within the Sudan People's Liberation Movement - the group that fought Sudan's army in the north for two decades. Machar led a splinter faction and south-south clashes erupted.
Machar is from the Nuer tribe which has fought in the past with South Sudan's dominant Dinka tribe, to which Kiir belongs.
"The divisions, largely along ethnic lines illustrate the embattled position the new nation's government is in," political risk consultants Eurasia Group said.
Critics say the new nation suffers the same ills as old Sudan, namely rampant corruption, poor public services and repression of government opponents and media.