President Pierre Nkurunziza returned to Burundi on Thursday, his office said, after the army chief declared that an attempted coup staged when the east African leader was abroad had failed.
But bursts of gunfire in the capital and fighting for control of the state radio during the day indicated there was still determined opposition to the president, who sparked protests and the coup attempt by his move to seek a third term.
Critics said his re-election bid violated the constitution and a peace deal that ended an ethnically fuelled civil war that ended in 2005, plunging the nation into a deep political crisis.
But before announcing his return, loyalists of the president said they were in control of the major strategic assets, such as the airport and presidential offices. They also said they still controlled the state broadcaster despite the heavy fighting.
"President Nkurunziza is back in Burundi after the attempted coup. He congratulates the army, the police and the Burundian people," said a brief phone text message from the presidency.
A presidential official confirmed the statement, but would not say where Nkurunziza was in Burundi or how he had returned.
Nkurunziza was in Tanzania at a summit of African leaders on Wednesday when Major General Godefroid Niyombare, who the president sacked as intelligence chief in February, declared he was dismissing the president and his government.
A day later, Army Chief of Staff General Prime Niyongabo said the coup had failed. "Loyal forces are still controlling all strategic points," he said in a state radio broadcast.
The announcement of Nkurunziza's return suggested the government was now back in effective control, although periods of relative calm in Bujumbura on Thursday were broken by bouts of gunfire. By evening, the city had a semblance of calm.
A Reuters witness saw one dead soldier lying near the Interior Ministry. Nearby troops said he was a coup supporter.
In an earlier broadcast, Nkurunziza offered amnesty to rebel troops. "I thank soldiers who are putting things in order, and I forgive any soldier who decides to surrender," he said.
But he is coming home to a nation where thousands of people in the capital spent more than two weeks protesting against his third-term election bid, often waging fierce street battles with police, and then cheered when his ouster was announced.
Nkurunziza justifies his bid for another five years in office by pointing to a constitutional court ruling which said the president could run because his first term, when he was picked by parliament rather than by popular vote, did not count. Critics say the court is biased.
Burundi's army is a symbol of national reconciliation but it has displayed alarming rifts.
In the civil war, the army was commanded by minority Tutsis who fought rebel groups of the majority Hutus, including one led by Nkurunziza. Now the military is a mixed ethnic force and has absorbed rival factions.
But the coup attempt suggested divisions in the ranks remain just below the surface, threatening a return to ethnic blood-letting that has worried Burundi's neighbours.
The United Nations says more than 70,000 Burundians have already crossed the borders for fear of an upsurge in violence, unsettling a region with a history of ethnic fighting.
African nations condemned the takeover attempt.
"East African leaders are determined to find a lasting solution to Burundi's crisis," Tanzanian Foreign Minister Bernard Membe said in Dar es Salaam. "Africa does not want the leadership of any country to be assumed by the barrel of a gun."
The African Union criticised any attempt to seize "power through violence" and called for dialogue to resolve the crisis.
The 15-nation U.N. Security Council said it would "respond to violent acts in Burundi that threaten peace and security" and condemned "those who facilitate violence of any kind against civilians and those who seek to seize power by unlawful means."
Western donors, which provide vital aid to finance Burundi's budget and other institutions, have urged Nkurunziza not to run again and have criticised the police crackdown on protesters.
After Wednesday's coup attempt, the United States, which helps train and equip the army, told all sides to end violence.
The European Union, Belgium and the Netherlands have all suspended some aid due to the unrest, particularly donations linked to the elections, which include parliamentary polls scheduled for May 26 and the presidential vote on June 26.