(Corrects name in paragraph 15 to show Nkurunziza was in Tanzania)
* President was in Tanzania when coup declared
* Loyalist general says troops control strategic points
* Location of president unclear, sources say in Tanzania
* Tanzania says no power transfer by "barrel of gun"
By Patrick Nduwimana
BUJUMBURA, May 14 (Reuters) - The head of Burundi's army said on Thursday that an attempted coup had failed and forces loyal to President Pierre Nkurunziza were in control.
Army Chief of Staff General Prime Niyongabo's announcement came a day after another general said he had sacked Nkurunziza for seeking an unconstitutional third term in office.
Gunfire could still be heard in the capital, Bujumbura, and whether the government had regained control was not clear.
The president, who was in Tanzania for an African leaders meeting on Wednesday when the attempt to topple him was announced, called on Burundians to "remain calm" in a message delivered via the presidential website and his Twitter feed.
There was no official confirmation about the whereabouts of the president, who sparked more than two weeks of protests by saying he would seek another five years in office. Two Tanzanian sources said he was in Dar es Salaam. One said he was at a "secure location".
"The coup attempt failed, loyal forces are still controlling all strategic points," Niyongabo said in a statement broadcast on state radio.
In Burundi's civil war that ended in 2005, the army was commanded by minority Tutsis who fought against rebel groups of the majority Hutus, including one led by Nkurunziza.
The military has since been reformed to absorb rival factions, but fault lines in its ranks have remained.
It was not immediately clear if the government was now fully back in control, although police had returned to some streets which they had left on Wednesday.
In one suburb, which had been a protest flashpoint, a group of young men who tried to walk to the centre of the city were blocked by police officers, a Reuters witness said. In another location, policemen were seen beating up a youth.
A journalist at the state broadcaster said heavy gunfire being was heard around the state television and radio station in the capital on Thursday morning, a Reuters witness said. Another reported loud blasts in the city.
The Reuters witness said two private radio stations and a television station were attacked by unknown men in police uniforms. The two stations were among those that carried Major General Godefroid Niyombare's announcement on Wednesday that he had sacked Nkurunziza.
Neither Niyombare nor his spokesmen were immediately available to comment.
While Nkurunziza was in Tanzania, the presidency dismissed the declaration by Niyombare, who was fired as Nkurunziza's intelligence chief in February, saying the coup had been "foiled".
Niyombare had said on Wednesday the capital's airport and all border crossings were closed. It was not immediately clear if that was still the case.
The East African leaders condemned the takeover attempt.
"East African leaders are determined to find a lasting solution to Burundi's crisis," Tanzanian Foreign Minister Bernard Membe told reporters. "Africa does not want the leadership of any country to be assumed by the barrel of a gun."
The continental body, the African Union, also condemned the attempted coup. AU Commission Chairwoman Nkosazana Dlamini Zuma called for "the return to constitutional order" in a statement.
Activists say more than 20 people have been killed in weeks of protest against Nkurunziza's re-election bid, plunging Burundi into its worst crisis since the civil war ended in 2005.
The United Nations said more than 70,000 Burundians had fled to neighbouring states in a region which has a history of ethnic fighting.
Western donors, which provide vital aid to finance the budget and other institutions, have criticised Nkurunziza for running again. The United States, which trains and equips the army, called on Wednesday for all parties to end violence.
Opponents say Nkurunziza's bid for another five years in office violates a two-term limit set down in the constitution and in the peace deal that ended the civil war.
A constitutional court, however, ruled that the president could run, finding that his first term, when he was picked by parliament rather than by popular vote, did not count. Critics say the court is biased. (Additional reporting by Aaron Maasho in Addis Ababa; Writing by George Obulutsa; Editing by Alex Richardson and Giles Elgood)