Turkish President Recep Tayyip Erdogan. (Turkish President Press Office Handout/EPA-EFE/Shutterstock)

WITH HIS growing authoritarianism, Turkey’s President Recep Tayyip Erdogan seemed unassailable a few months ago when he decided to advance presidential and parliamentary elections by more than a year, to June 24. His heavy-handed tactics portended more hostility toward the West and repression at home if he won. But now there are welcome signs that Mr. Erdogan and his party are facing unexpected head winds.

A key turning point came recently when fractured opposition parties came together in an alliance, with the exception of the pro-Kurdish Peoples’ Democratic Party, and agreed to back a single presidential candidate in any second round against Mr. Erdogan. The alliance has been forged in part out of a determination to stop Mr. Erdogan’s push to consolidate power with authoritarian tactics. Since a failed coup attempt in 2016, the Turkish authorities have detained 160,000 people, including journalists, civil servants and professors, in a drive to root out Mr. Erdogan’s perceived enemies and opponents.

The election is for a new, more powerful executive presidency narrowly approved by voters last year in a referendum. If Mr. Erdogan wins, he will enjoy unparalleled power. However, by forming a unified front, the opposition alliance could deny Mr. Erdogan’s Justice and Development Party, or AKP, and its allies a majority in parliament — thus posing a roadblock to Mr. Erdogan’s ambitions. Polls show this outcome in parliament is a possibility; support for the AKP has slid precipitously in recent months.

The polling also suggests that Mr. Erdogan may not win the presidency on the first ballot and may be forced into a runoff. This could further take the edge off his air of invincibility, and a spirited second round could pose the most serious challenge to him in years. Still, Mr. Erdogan will enjoy big advantages, not least of them because he practically wiped out independent journalism in recent years and silenced many critical voices in civil society.

The wild-card factor is the economy. Robust growth has been Mr. Erdogan’s strength, but with inflation and unemployment rising, the currency, the lira, has taken a plunge , and lost more than 20 percent against the dollar this year alone. As a report last week from the Brookings Institution pointed out, social media has been alive with catchphrases that suggest impatience and fatigue with the AKP and Mr. Erdogan, who has ruled Turkey for more than 15 years.

It certainly would be refreshing to see voters reject Mr. Erdogan’s illiberal autocracy and demonstrate anew their support for democracy. It also might slow Turkey’s drift away from Europe and the United States. Mr. Erdogan is the most adroit Turkish politician in decades and should not be underestimated, but a backlash may be brewing. That gives good reason to Western governments, including the Trump administration, not to write off the Turkish election as a foregone conclusion but to follow it closely — and insist that the votes be counted fairly and the results respected.