ARTICLE AD BOX
By Orla Guerin
BBC News, Ankara
Recep Tayyip Erdogan may have serenaded his supporters by singing off-key after his victory - but he is pitch perfect when it comes to fighting elections.
He read the electorate better than the pollsters and analysts, who suggested he could be beaten by the opposition. Well, not this time.
His opponent - Kemal Kilicdaroglu - was just four percentage points behind him. No doubt President Erdogan will be reflecting on that as he starts his third term in office.
This strategic Nato nation has chosen its path, most voters opting for a season autocrat rather than an untested democrat in the form of Mr Kilicdaroglu.
The opposition leader ran his campaign as Mr Nice Guy, initially promising a new spring for Turkey. He later swerved right, vowing to send all refugees home. That won his some extra support from nationalists, but not enough.
Turkey's Islamist leader Mr Erdogan has a bond with his followers that goes back 20 years. Many are religious conservatives like him. They have stuck with him through thick and thin - and hyperinflation - giving him five more years.
As the run-off result was announced, the streets of the capital Ankara were a kaleidoscope of Turkish flags, blaring car horns, and cheering Erdogan supporters. Huge numbers flocked to his custom-built presidential palace with its 1,000 plus rooms. His rival had promised to put it in public use.
"We were blessed by the fact that our president is again leading us," said Hatice Duran, 50, who was smiling broadly beneath her headscarf. "There is no other feeling greater than this. Let the world hear this. He is the leader who defied the entire world and taught the entire world a lesson."
That's a key part of his appeal here: Mr Erdogan is a strong leader, a latter-day Sultan who does not bow down.
The message of the election is that many here prefer a tough guy to a nice guy.
Now he is newly emboldened. The country's opposition is badly bruised, and the Kremlin is celebrating.
This is the outcome President Vladimir Putin wanted - no surprises that he was one of the first to offer his congratulations to the Turkish leader. Mr Putin did what he could to tilt the scales in his favour, including postponing a $600m (£486m) payment for Russian natural gas.
Mr Erdogan entered the contest with many advantages: his street smarts, his common touch, and his control of 90% of the media here.
In his victory speech he insisted that "only Turkey was the winner" - but he lost no time in attacking the opposition and the LGBTQ community.
Both may now be targeted even more, and human rights and free speech could be further eroded in the years to come. There are few checks and balances here, and Turkey's longest-serving leader is not known for his restraint.
Those who wanted change here - almost 48% of the voters - will be disappointed, and perhaps fearful.
Many predict there will be more religion and less freedom in the public life of this secular republic, which will mark its centenary in October.
Turkey is now a divided nation with a broken economy. Critics say the president has no solution for either.
And where does the election result leave Turkey's neighbours and its Nato allies? They will be watchful, knowing President Erdogan often seems to relish upending the established international order.