* U.N. envoy appeals to leaders for calm
* President declares curfew in Juba
* 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 clashes overnight between rival factions of soldiers following months of tension between Kiir and his sacked deputy.
Kiir blamed soldiers loyal to Riek Machar, who was 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 rival ethnic groups which have clashed in the past.
Flanked by ministers and wearing combat fatigues rather than civilian clothes, Kiir declared an overnight curfew in Juba effective from Monday night. It will run each night from 6 p.m. to 6 a.m.
He said the fighting broke out after an unidentified person had fired shots in the air near a ruling party conference.
"This was followed later by an attack at the SPLA 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 Juba, intensifying on Monday morning but later subsiding. The U.N. envoy for South Sudan said called for calm.
The government has struggled to establish a functioning state since declaring independence from Sudan in 2011 to become Africa's newest nation.
Kiir had dismissed Machar after mounting public criticism at the government's failure to deliver better public serices in the oil-producing nation, which is the size of France but barely has any tarmac roads.
Machar has said he wants to run for president in future.
Clashes were concentrated at two military bases, the main Bilpam barracks north of the airport, and the Jebel barracks south of Juba, where the presidential guard is based, residents said. Travel in the city was restricted and flights were halted.
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.
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 shutdown 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."
A U.N. spokeman said about 800 civilians had taken shelter in a U.N. compound near the airport. Speaking by telephone, he said seven people had been treated for gunshot wounds, including a two-year-old boy.
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." (Additional reporting by Pascal Fletcher in Johannesburg and Drazen Jorgic in Nairobi, Writing by Edmund Blair, Editing by Angus MacSwan)