The clashes broke out in a barracks close to the city centre shortly before midnight and spread across the city, diplomats and witnesses said, adding that heavy machine guns and mortars were used.
The UN said hundreds of terrified civilians had sought refuge in a United Nation compound, while across the city most residents locked themselves in their homes, an AFP reporter said.
"This was an attempted coup," President Salva Kiir said, blaming his arch-rival -- former vice president Riek Machar who was sacked from the government in July -- for starting the violence.
"I will not allow or tolerate such incidents once again in our new nation. I strongly condemn these criminal actions in the strongest terms possible," he added.
More From This Section
He said an overnight curfew would be imposed from 6:00 pm today to 6:00 am tomorrow and remain in force until further notice. Army spokesman Phil Aguer also told local radio that troops loyal to the president were "in control of the situation".
Statements from the US and British embassies in Juba urged their nationals to avoid unnecessary movements. The US embassy said there hade been "incidents and sporadic gunfire in multiple locations across Juba" throughout the night.
A diplomat in the city said troops loyal to the president had been posted at major intersections. Civil aviation and airline sources also said that Juba airport had been shut indefinitely, while the country's borders with Uganda and Kenya were reportedly shut.
Oil-rich but impoverished South Sudan won its independence in 2011 after its people voted overwhelmingly in a referendum to split from the north and form a new nation.