* 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) - South Sudan's President Salva Kiir declared a curfew in the capital Juba on Monday after overnight clashes between rival factions of soldiers that he said were triggered by an "attempted coup".
Kiir blamed soldiers loyal to Riek Machar, who he dismissed as vice-president in July, for starting the fighting in the capital that extended into Monday morning before easing.
The two men are from different ethnic groups which have clashed in the past. Machar has said he wants to run for president.
Flanked by ministers and wearing combat fatigues rather than his usual civilian clothes, Kiir declared a curfew running from 6 p.m. to 6 a.m. each night, effective from Monday.
Kiir 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."
Gunfire and blasts were heard through the night around the city, intensifying on Monday morning. Fighting mostly subsided by midday, with witnesses reporting sporadic gunfire in some areas and a heavy military presence in the city.
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. Women and children were among the thousands taking shelter, said the U.N. Office for the Coordination of Humanitarian Affairs.
The U.S. Embassy in Juba said on its Twitter account that mobile phone networks were off in the capital.
Kenyan airlines Fly540 and Kenya Airways suspended flights indefinitely to Juba after the airport closed.
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.
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.
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.
CALLING FOR RESTRAINT
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. "I have been in touch regularly with the key leaders to call for calm."
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" where 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.
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.
The Twitter account of the U.S. Embassy in South Sudan denied rumours Machar had taken refuge at the base and said the mission was monitoring the security situation.
"The majority of citizens are yearning for peace," said Atem Yak Atem, a former deputy minister of information who now runs a media consultancy. "People are calling for a negotiated settlement among the politicians."