ISTANBUL -- Turkish President Recep Tayyip Erdogan won a historic referendum Sunday that will greatly expand the powers of his office, although opposition parties questioned the outcome and said they would challenge the results.

With nearly all ballots counted, the "yes" vote stood at 51.41 per cent, while the "no" vote was 48.59 per cent, according to the state-run Anadolu Agency. The head of Turkey's electoral board confirmed the "yes" victory and said final results would be declared in 11-12 days.

Although the margin fell short of the sweeping victory Erdogan had sought in the landmark referendum, it could nevertheless cement his hold on power in Turkey and is expected to have a huge effect on the country's long-term political future and its international relations.

The 18 constitutional amendments that will come into effect after the next election, scheduled for 2019, will abolish the office of the prime minister and hand sweeping executive powers to the president.

Erdogan, who first came to power in 2003 as prime minister, had argued a "Turkish-style" presidential system would bring stability and prosperity to a country rattled by a failed coup last year that left more than 200 people dead, and a series of devastating attacks by the Islamic State group and Kurdish militants.

In his first remarks from Istanbul after the vote count showed the amendments winning approval, Erdogan struck a conciliatory tone, thanking all voters no matter how they cast their ballots and calling the referendum a "historic decision."

"April 16 is the victory of all who said 'yes' or 'no,' of the whole 80 million, of the whole of Turkey," Erdogan told reporters in a live televised address.

But he quickly reverted to a more abrasive style when addressing thousands of flag-waving supporters in Istanbul.

"There are those who are belittling the result. They shouldn't try, it will be in vain," he said. "It's too late now."

Responding to chants from the crowd to reinstate the death penalty, Erdogan said he would take up the issue with the country's political leaders, adding that the question could be put to another referendum if the political leaders could not agree.

He also took a dig at international critics. During the referendum campaign, Ankara's relations soured with some European countries, notably Germany and the Netherlands. Erdogan branded officials in the two nations as Nazis for not allowing his ministers to campaign for the expatriate vote there.

"We want other countries and organizations to show respect to the decision of our people. We expect countries that we accept as our allies to show more sensitivity to our fight against terrorism," he said.

Opponents had argued the constitutional changes would give too much power to a man who they say has shown increasingly autocratic tendencies. Opposition parties complained of a number of irregularities in the voting, and were particularly incensed by an electoral board decision announced Sunday afternoon to accept as valid ballots that did not bear the official stamp.

"The Supreme Electoral Board changed rules mid-game, after the ballot envelopes were opened, in a way contrary to laws," said Kemal Kilicdaroglu, head of the main opposition People's Republican Party. Earlier, the party's vice chairman, Erdal Aksunger, said it would challenge between 37 per cent and 60 per cent of the ballot boxes and accused Anadolu's results of being inaccurate.

But electoral board head Sadi Guven defended the decision.

"There is no question of changing the rules in the middle of the game," he said.

A pro-Kurdish opposition party that also opposed the constitutional changes said it plans to object to two-thirds of the ballots.

Given the contested outcome, Fadi Hakura, Turkey specialist at the London-based think-tank Chatham House, described Erdogan's win as a "pyrrhic victory that comes at a huge political cost. The result will depend on how far the opposition will take their claim of irregularity in the voting, and what the international reaction will be."

"Erdogan has claimed victory, but there are question marks that are being raised," Hakura said.

Initial reaction from abroad was cautious. Three top officials for the European Union -- EU Commission chief Jean-Claude Juncker, EU foreign policy chief Federica Mogherini and Enlargement Commissioner Johannes Hahn -- said in a joint statement they "take note of the reported results" and were awaiting a report from international election observers.

Austrian Foreign Minister Sebastian Kurz said the referendum was bound to complicate further co-operation between Ankara and the EU. Kurz said on Twitter the result "shows how divided the country is. Cooperation with .EU will become even more complex."

The referendum campaign was highly divisive and heavily one-sided, with the "yes" side dominating the airwaves and billboards. Supporters of the "no" vote have complained of intimidation, including beatings, detentions and threats.

"Erdogan dominated the national media. He imposed a very restrictive environment for the 'no' camp. He secured a thin majority of 1 per cent," Hakura said. "This suggests that Erdogan will become more robust and more challenging to deal with."

More than 55 million people were registered to vote, while another 1.3 million expatriates cast ballots abroad. The ballots themselves did not include the referendum question -- it was assumed to be understood.

The changes will allow the president to appoint ministers, senior government officials and half the members of Turkey's highest judicial body, as well as to issue decrees and declare states of emergency. They set a limit of two five-year terms for presidents and also allow the president to remain at the helm of a political party.

Opponents fear the changes will lead to autocratic one-man rule, ensuring that the 63-year-old Erdogan, who has been accused of repressing rights and freedoms, could govern until 2029 with few checks and balances.

In Istanbul, hundreds of demonstrators opposed to the amendments marched in a central neighbourhood late Sunday, clanging pots and pans and chanting, "This is just the beginning, the struggle will continue."

The vote came as Turkey has been buffeted by problems. Erdogan survived a coup attempt last July, which he has blamed on his former ally and current nemesis Fethullah Gulen, an Islamic cleric living in the United States. Gulen has denied involvement.

A widespread government crackdown has targeted Gulen followers and other government opponents, branding them terrorists. A state of emergency has been imposed.

About 100,000 people -- including judges, teachers, academics, doctors, journalists, military officials and police -- have lost their jobs in the crackdown, and more than 40,000 have been arrested. Hundreds of media outlets and non-governmental organizations have been shut down.

Turkey has also suffered renewed violence between Kurdish militants and security forces in the country's volatile southeast, as well as a string of bombings, some attributed to the Islamic State group, which is active across the border in Syria.

The war in Syria has led to some 3 million refugees crossing into Turkey. Erdogan sent troops into Syria to help opposition Syrian forces clear a border area from the threat posed by Islamic State militants.

------

Fraser reported from Ankara. Bram Janssen in Istanbul and Mucahit Ceylan in Diyarbakir also contributed to this report.