Recep Tayyip Erdoğan has addressed thousands of supporters in Ankara after being declared the victor in Turkey’s presidential election, saying democracy was the winner and that Turkey was “an example for the rest of the world”.

“We have received the message that has been given to us in the ballot boxes,” he said, speaking from the balcony of the AK party’s headquarters in Ankara, to a large crowd of cheering and flag-waving supporters. “We will fight even more with the strength you provided us with this election.”

He began by apologising for being late to the balcony speech, saying this was due to the fact that a small child was injured in the crowd in Istanbul, where he had been speaking before, and he went to speak to the child’s family.

Erdoğan spoke of his commitment to “fight terroristic organisations”, “to continue the fight to make the Syrian grounds freer” and to increase the “international prestige” of Turkey, saying: “Turkey has no moment to waste, we know that.”

“Our flag will flutter more freely, the peace of every citizen will be advanced,” he said, before leading the crowd in a chant of “One nation, one flag, one country, one state.”

Earlier on Sunday night, the country’s electoral board said the incumbent had won with 97.7% of votes counted. Even before this declaration, Erdoğan seemed sure of the result.

“Our people have given us the job of carrying out the presidential and executive posts,” Erdoğan said on Sunday night, even while ballots were still being tallied. “I hope nobody will damage democracy by casting a shadow on this election and its results to hide their failure.”

The main opposition party did not immediately concede defeat, but after initially saying Erdoğan would fall well short of a first-round victory, it later said it would continue its democratic struggle “whatever the result”.

Totalitarian tyrant or trusted leader? Turkish voters split on Erdoğan Read more

The official Anadolu Agency reported that, with 99% of votes counted, Erdoğan had won a 52.54% share of the national vote, while the opposition CHP party’s candidate, Muharrem İnce, was on 30.68%.

The pro-Kurdish party, known as the HDP, took 11.67% of the vote, passing the 10% threshold to enter parliament for a second consecutive term. This diluted the majority of Erdoğan’s ruling party, the AKP, but fell short of the numbers needed to overturn that majority after a surprise showing by the AKP’s nationalist allies.

“This sets the stage for speeding up reforms,” the Turkish deputy prime minister, Mehmet Şimşek, tweeted of the results.

The winner of the presidential race is set to assume extraordinary new powers narrowly approved in a referendum last year that was marred by allegations of fraud. These include complete control of the cabinet and the power to appoint senior judges and officials, including unelected vice-presidents. The president will also have the power to issue decrees with the force of law.

Those powers will allow the victor to transform Turkey’s political scene for years and possibly decades to come, governing until 2028 if he wins re-election. Opposition candidates had pledged to overturn the presidential system if they had won.

The results, if they stand, will be a disappointment to the opposition, which had hoped to push Erdoğan into a second-round runoff against İnce, and to wrest control of the legislature from the AKP. Erdoğan and his party have governed unopposed for 16 years.

The president called early the snap elections in April hoping to preempt worsening economic trends and to catch the opposition by surprise. He looked set to win easily in a presidential race and in parliament in alliance with the nationalists, projecting an image of a commander-in-chief fighting external enemies inside Turkey and across the border in Syria, and triumphant against terror groups.

But the opposition mounted a dynamic election campaign, with its presidential candidate İnce drawing crowds in the hundreds of thousands in rallies in the country’s largest cities of Istanbul, İzmir and Ankara, and criss-crossing the country on dozens of rallies.

Turnout at the elections hovered around an extraordinary 87% of the electorate, exceeding that of last year’s referendum.

Opposition officials cried foul as soon as results began coming in, with the state-run Anadolu Agency announcing preliminary results more than two hours earlier than expected and opening with a massive lead for Erdoğan and his party’s alliance in parliament.

That lead closed over time, but it prompted accusations by the opposition that the state news agency was launching a manipulation operation to influence election monitors into leaving ballot counting stations early.

For much of the count, rival vote estimates by the opposition and the state-run agency were published, the former showing Erdoğan winning with less than 50% of the vote, and the latter showing a first-round outright victory.

The first result would lead to a second-round contest on 8 July, a possibility that would represent a major psychological blow for Erdoğan, even if he was tipped to win that contest as well.

The main secular opposition party, İnce’s CHP, continued to contest the results well into the count, charging that less than 40% of ballot boxes had been opened, and that many of İnce’s strong electoral districts had not yet been counted.

İnce urged ballot count monitors to remain at their stations until the counts had been completed to protect against election fraud.

Nevertheless, Erdoğan had already been congratulated on a win in the race by Hungary’s strongman leader, Viktor Orbán.

The election took place on an uneven playing field, against a backdrop of human rights abuses that Amnesty International described as a “climate of fear”.

One of the presidential candidates, Selahattin Demirtaş, ran his presidential campaign from a prison cell in Edirne where he is on trial on terrorism charges. The government has either shuttered, bought or taken over newspapers and TV stations, transforming the vast majority of the nation’s media into a loyalist press.

Thousands of people have been detained or dismissed since a coup attempt in 2016, a crackdown that has gone beyond the followers of Fethullah Gülen, the man accused of masterminding the coup from his exile in Pennsylvania, to dissidents of all stripes including academics, students who opposed military incursions into Syria, judges, bureaucrats and police and military officers.

Nevertheless, there were few incidents of apparent electoral fraud, with the exception of the province of Urfa, where some apparent attempts to rig the vote were uncovered during the course of the day. Poll stations opened at 8am and closed at 5pm.