Turkish President Recep Tayyip Erdogan narrowly won a historic referendum on Sunday that will tighten his grip on power, but the knife-edge result left the country bitterly divided and the opposition crying foul.
The sweeping constitutional changes approved in the vote create a presidential system that will grant Erdogan more power than any leader since modern Turkey's founder Mustafa Kemal Ataturk and his successor Ismet Inonu.
The result could also have even wider implications for Turkey which joined NATO in 1952 and for the last half-century has set its sights on joining the European Union.
The "yes" campaign won 51.4 percent of the vote against 48.6 percent for "no," the election commission said in figures quoted by state news agency Anadolu, in a count based on 99.5 percent of the ballot boxes. Turnout was a high 85 percent.
As huge crowds of flag-waving supporters celebrated on the streets, Erdogan praised Turkey for taking a "historic decision."
"With the people, we have realized the most important reform in our history," he added.
But opposition supporters in anti-Erdogan districts of Istanbul showed their dissatisfaction by bashing pots and pans with kitchen utensils to create a noisy protest. Hundreds also took to the streets in the areas of Besiktas and Kadikoy.
Related: Young Turkish activists prove it will be hard for Erdogan to shut down free expression
Supreme Election Board chief Sadi Guven confirmed that the "yes" camp had emerged victorious, but the opposition has vowed to challenge the outcome.
The referendum was held under a state of emergency that has seen 47,000 people arrested in an unprecedented crackdown after a failed military putsch against Erdogan in July last year.
In a nail-biting end to a frenetic campaign, the "no" share of the vote climbed as more ballots were counted, after lagging well behind in the early count, but failed to overtake the "yes" votes.
"This is a decision made by the people. In our democracy's history, a new page has opened," said Prime Minister Binali Yildirim, whose job will disappear under the constitutional changes.
In a television interview on Friday Erdogan had predicted a far clearer victory saying polls showed a 55-60 percent share of the vote.
But voting patterns showed Turkey deeply divided over the changes, with the "no" vote victorious in the country's three biggest cities.
The "yes" vote held up strongly in Erdogan's Anatolian heartland but the Aegean and Mediterranean coastal regions and Kurdish-dominated southeast backed the "no" camp.
In a major disappointment for the president, the "no" vote was just ahead in his hometown of Istanbul and in the capital Ankara and clearly ahead in the third city of Izmir.
A statement issued by European Commission head Jean-Claude Juncker and EU foreign affairs chief Federica Mogherini said that in view of the closeness of the result, the Turkish authorities need to seek the "broadest possible national consensus" for the changes.
Erdogan made relations with the EU a key issue in his referendum campaign, lambasting Brussels for failing to make progress on Ankara's stalled accession talks and he accused Germany and the Netherlands of acting like the Nazis when they barred pro-government rallies.
Related: Turkish women's rights are at stake in Sunday's elections
Turkey's two main opposition parties said they would challenge the results over alleged violations.
The pro-Kurdish Peoples' Democratic Party (HDP) said it would challenge two-thirds of the votes, saying: "There is an indication of a 3-4 percentage point manipulation of the vote."
Republican People's Party (CHP) chief Kemal Kilicdaroglu said the actions of the election authorities "caused the referendum's legitimacy to be questioned" insisting that the "no" side had won at least 50 percent of votes cast.
"Believe me, this election is not over," deputy CHP leader Erdal Aksunger told CNN Turk, quoted by the Dogan news agency. "This is totally invalid. We are declaring this here."
The opposition had already complained that the referendum was conducted on unfair terms, with "yes" posters ubiquitous on the streets and opposition voices squeezed from the media.
Closely watched on Monday will be the initial assessment of the international observer mission of the OSCE Office for Democratic Institutions and Human Rights (ODIHR) and the Parliamentary Assembly of the Council of Europe (PACE).
Erdogan again warned Brussels he would sign any bill agreed by parliament to reinstate capital punishment, a move that would automatically end Turkey's EU bid.
If the opposition failed to support the bill, Erdogan said another referendum could be held on reinstating the death penalty.
Western reactions to the referendum will be crucial after Erdogan accused Turkey's allies of failing to show sufficient solidarity in the wake of the failed coup.
"We would like other countries and institutions to show respect to the decision of the nation," Erdogan said.
The new system would dispense with the office of prime minister and centralize the entire executive bureaucracy under the president, giving Erdogan the direct power to appoint ministers.
It is due to come into force after elections in November 2019. Erdogan, who became president in 2014 after serving as premier from 2003, could then seek two more five-year terms.
"I don't think he (Erdogan) will reverse course. I don't think Erdogan will change the robust and muscular approach to politics that he has adopted so far," said Fadi Hakura, Turkey expert at London-based Chatham House think tank.
Related: President Trump, will you remove US nuclear weapons from Turkey?
Our coverage reaches millions each week, but only a small fraction of listeners contribute to sustain our program. We still need 224 more people to donate $100 or $10/monthly to unlock our $67,000 match. Will you help us get there today?