Nine months ago, after fighting off a coup attempt, Turkish President Recep Tayyip Erdogan vowed that his opponents would pay a heavy price. And pay they did: The autocratic-minded president embarked on a sweeping purge that left nearly 170,000 compatriots, viewed by the president as enemies, either behind bars or forced from their jobs.
Now the Turkish leader may be setting his sights on another perceived foe: the West.
The confrontation, were it to escalate, could have lasting repercussions for the U.S.-led fight against the militants of Islamic State, Europe's migrant crisis and perhaps even the NATO alliance, of which Turkey is one of only two Muslim-majority members. It has the bloc's second-largest military.
Erdogan had hoped to put a final seal on his consolidation of power this week by decisively winning a referendum that replaces Turkey's century-old parliamentary democracy with a "presidential system." It greatly expands the president's authority and would allow Erdogan to serve for an additional 15 years in office.
But the margin of victory in Sunday's balloting was razor-thin, and the vote's legitimacy was sharply questioned by both domestic opponents and foreign observers.
The opposition Republican People's Party on Monday demanded the annulment of the constitutional referendum, charging that the rules for counting ballots were changed illegally in the midst of voting. And observers from the Council of Europe issued a scathing report, saying the campaign took place on an "unlevel playing field" and that the rules for organizing the referendum were not up to international standards.
For the 63-year-old leader, the muddied result was a fury-inducing affront. Addressing supporters in the Turkish capital, Ankara, on Monday, Erdogan denounced the "crusader mentality in the West" — a loaded reference to Europe's medieval holy wars aimed at Islam.
Bashing the West, particularly Europe, is a well-thumbed page in the Erdogan playbook, a sure-fire way of appealing to his conservative, nationalistic base at home.
In recent months, the Turkish president has quarreled repeatedly and publicly with European leaders. Most recently, he accused the Netherlands and Germany of Nazi-like behavior when they prevented Turkish politicians visiting those countries from campaigning for the referendum in front of crowds of expatriate Turks.
This time, though, a leader who had once touted himself as a bridge between East and West appeared determined to issue a rebuke to Europe that was more than symbolic. At several appearances Monday, he emphasized his readiness to restore the death penalty, a step that would all but kill Turkey's decades-long campaign to join the European Union.
Playing to popular Turkish sentiment, Erdogan has also said the question of whether to continue seeking EU membership should be put to a referendum.
"That resonates well with his constituency, and beyond," said Gonul Tol, the director of the Middle East Institute's Center for Turkish Studies. "If you talk to a regular Turk in the street about the European Union, you hear this often: 'They won't accept us because we're Muslim.'"
While Erdogan may be grappling with Europe, he seems to have retained one Western friend: Donald Trump.
In a remarkably friendly telephone conversation, Trump congratulated Erdogan for the referendum victory, apparently ignoring the narrow margin, allegations of fraud and criticisms of overreaching power, according to an account released by the White House.
Instead, Trump focused on Syria, the "importance of holding Syrian President Bashar al Assad accountable" for the recent chemical attack on his people and the fight against Islamic State, the White House said. He thanked Erdogan for his support.
Turkey's growing estrangement comes at a time when Ankara's cooperation with the West is at a premium. Europe needs Turkey to continue stemming the flow of refugees to its shores via the short sea voyage from Turkey to Greece. And Turkey is an important partner in the anti-Islamic State coalition, with the U.S. using Turkey's sprawling Incirlik Air Base as a major staging ground.
But Turkey's own needs are more in play in its dealings with Washington than with Europe, Tol and others said.
"The government still very much values its partnership with the United States," said Tol. That relationship, she said, remained strong despite tensions over Turkey's unfulfilled demand for the extradition of self-exiled cleric Fethullah Gulen, who lives in Pennsylvania and is blamed by Erdogan for fomenting July's attempted coup.
The referendum result left little doubt that Erdogan is presiding over a deeply polarized country, already beset by violent spillover from the war in Syria and a flaring Kurdish insurgency. The Turkish leader had argued that the wholesale overhaul of the republic's political structure would help stave off instability.
Official results were not expected for 10 or 12 days, but Turkish election authorities said preliminary results gave a majority of 51.41% to 48.59% to the package of 18 constitutional amendments.
The vote illustrated long-standing divisions: secular Turks pitted against more pious Muslims, cosmopolitan urbanites versus the conservative rural heartland, and tensions between those who embrace a Turkish role in the wider world and homegrown nationalists.
Erdogan has been in power since 2003, his rise coinciding with Turkey's emergence as an industrial dynamo, though its economy has since faltered, and as a regional heavyweight, with a large footprint in Syria's civil war.
The consolidation of authority makes Erdogan the most consequential Turkish leader since Kemal Ataturk, the founding father of the republic that arose from the ruins of the Ottoman Empire. Erdogan often harks back to past imperial glory with grandiose gestures like the construction of a lavish 1,000-room Ottoman-themed presidential palace.
Mindful of Erdogan's reputation for holding fast to grudges, European leaders urged him to consider the narrow referendum result a mandate to reach out to his political opponents. German Chancellor Angela Merkel, in a statement issued along with her foreign minister, said the closeness of the contest pointed to a "big responsibility for the Turkish leadership and for President Erdogan personally."
But analysts expressed doubt such rapprochement would occur, with the exception of a possible effort by Erdogan to try to mend fences with the Kurds and restart negotiations aimed at halting the insurgency.
"He's a double-down kind of guy — he's not going to be more moderate and reach out to the opposition," said James Jeffrey, a former ambassador to Turkey who is now an analyst with the Washington Institute.
The bitterness was apparent on both sides of the referendum question.
"This referendum will take its place in the dark pages of history," said Bulent Tezcan, the deputy leader of the Republican People's Party, or CHP. "This referendum will always be remembered as illegitimate."
The CHP, founded by Ataturk, called for annulment of the result. Its primary complaint was that ballots are required by law to have the stamp of the Supreme Board of Elections to be valid, but the board decreed midway through the voting that unstamped papers were valid unless there was clear evidence of fraud.
The CHP said at least 1 million ballots were stamped after they were handed in. That's close to the winning margin for "yes," which according to unofficial results received 24.3 million votes, compared to 23.2 million for "no" votes.
The report by the international referendum observer mission, meanwhile, said the legal framework for the vote was inadequate for a genuinely democratic referendum. It also faulted Turkish authorities for holding the vote during a state of emergency, under which the government issued decrees that affected the outcome but could not be challenged.
The observers were from the Organization for Security and Cooperation in Europe, which monitors compliance with human rights norms, and the Council of Europe, which sets them. They complained that coverage by the news media, which has been significantly purged of critical voices under Erdogan, was significantly imbalanced, with three-quarters of the coverage going to the "yes" campaign.
Special correspondent Gutman reported from Istanbul and staff writer King from Washington. Staff writer Tracy Wilkinson contributed to this report from Washington.
8:50 p.m.: The article was updated with news of President Trump's phone call to Erdogan.
5:05 p.m.: This article has been updated throughout with details, quotes, background, analysis.