Mr Nkurunziza said he had come back on the Burundi presidency Twitter site.
There were earlier fierce clashes in the capital, Bujumbura, particularly at the state radio office, but they are now said to have subsided. Five soldiers are reported killed.
Mr Nkurunziza had been in Tanzania when the coup began on Wednesday.
Protests began in Burundi on 26 April when Mr Nkurunziza announced he was seeking a third term, a move his opponents said was unconstitutional.
The coup was launched by Maj Gen Godefroid Niyombare, a former ally of the president, on Wednesday after Mr Nkurunziza travelled to Dar es Salaam, Tanzania’s largest city, to attend a summit on the crisis.
There were no new statements from Gen Niyombare on Thursday but a spokesman for the coup forces, Gen Cyrille Ndayirukiye, told Agence France-Presse the uprising had failed.
“We faced an overpowering military determination to support the system in power,” he said.
Burundian presidential spokesman Willy Nyamitwe told the BBC on Thursday that the president had left Tanzania and was “safe and sound”.
He later confirmed that Mr Nkurunziza was in Burundi but would give no more details due to “security reasons”.
He had earlier told Radio France Internationale: “The loyalist army is present, his advisers are present and the government is present. The country, then, continues to function.”
In his Twitter posting, Mr Nkurunziza said: “I thank the army and police for their patriotism. Above all I thank Burundians for their patience.”
‘Fighting has stopped’
Army chief of staff Gen Prime Niyongabo told the BBC’s Maud Jullien the number of soldiers backing the coup had fallen.
“On Wednesday evening we gave them the chance to rejoin the army to avoid a bloodbath. But they tried to attack the radio station today – the army repelled the attack.
“We are in control of all strategic points in the country. Burundi is a democratic nation. The army does not interfere in politics. We are obliged to follow the constitution.”
Our correspondent says it is believed that many of the coup forces have now retreated to the military base from which the attempt to overthrow the president was announced.
BBC reporters say the streets seem to be mainly in the control of loyalist police, and the airport has reopened, which would appear to confirm reports it too is in loyalist hands.
Fighting had erupted at the state radio building after the RTNB station broadcast a message from Mr Nkurunziza condemning the coup.
“I thank soldiers who are putting things in order, and I forgive any soldier who decides to surrender,” he said.
At the scene: Ruth Nesoba in Bujumbura
It is quiet in the streets in the centre of Bujumbura at the moment and I can see that some people have ventured out.
In the morning we woke to the news that the loyalists had launched an attack on private radio stations, which were taken off air, and then there was a struggle between rival factions in the army over control of the national broadcaster. The TV is not on air, but radio is playing Kirundi music. The broadcasts have been on and off.
There is no confirmation about the whereabouts of Gen Niyombare and we have not heard from him since his announcement of the coup on private radio on Wednesday.
The station briefly stopped broadcasting during the attack.
But station director Jerome Nzokirantevye was soon back on air, saying: “Now the fighting has stopped we can resume. It is still loyalist soldiers who are in control.”
Control of the national broadcaster is key because it is the only outlet still broadcasting outside the capital.
The two private radio stations have been shut down. The most popular – Radio Publique Africaine – was burnt down overnight after broadcasting the coup announcement.
Thousands of people had taken to the streets on Wednesday to celebrate the announcement of the coup, marching on the centre of Bujumbura alongside soldiers.
Tens of thousands flee
The unrest began after the 51-year-old president said he would run for re-election in June.
Opponents said this contravened the constitution, which states a president can only be elected to two terms.
Mr Nkurunziza argued he was entitled to a third term because he was first appointed to the role by parliament in 2005, rather than elected.
Earlier this month, the country’s constitutional court upheld his interpretation.
More than 20 people have died and tens of thousands of Burundians have fled to neighbouring states since the unrest began.
Coup bid leader: Gen Godefroid Niyombare, 46
- Former rebel CNDD-FDD commander and ally of President Nkurunziza
- First ethnic Hutu army chief – a significant step in reconciliation efforts
- A negotiator in peace talks with last rebel group FNL
- Oversaw Burundi’s deployment to Somalia as part of African force
- Served as ambassador to Kenya
- Dismissed as intelligence chief in February three months after his appointment
- Dismissal came days after he recommended against the third-term bid