IT IS rare for somebody who wins more than 40% of the vote to feel beaten. But after the Turkish general election on June 7th that is the fate of the Justice and Development (AK) party and, even more so, of Recep Tayyip Erdogan (pictured), its charismatic and worryingly autocratic founder. As head of state, Mr Erdogan is supposed to stand above party politics, but he campaigned shamelessly for an AK supermajority that could change the constitution to create a strong executive president (ie, himself). The verdict? AK’s support fell from almost 50% in 2011 to 40.9% and the party lost its majority in parliament.

By slashing AK’s share of the vote and, especially, by putting the pro-Kurdish People’s Democratic Party (HDP) well over the 10% threshold for parliamentary seats, Turks have unambiguously repudiated Mr Erdogan’s ambitions for a strong presidency. Most of them now dislike the sectarian Sunni rhetoric, the intolerance of opposition and the stench of corruption that, after 12 years in office, have come to characterise Mr Erdogan’s rule.

Although the election result has created big uncertainty over the formation of a new government, it is still welcome. Mr Erdogan’s early reforms were relatively liberal. Under him, the economy until recently did well. But, steered by his Islamist and neo-Ottoman instincts, Turkey has more recently drifted away from its NATO allies, especially over the Middle East. And his despotic behaviour undermined the rule of law, freedom of speech and Turkey’s independent institutions. Had he persuaded voters to back his executive presidency, the very future of Turkish democracy would have been at risk.

Eroding Erdogan's power: Our guide to Turkey's general elections The right course for Mr Erdogan now is to pull back from the fray and act as the apolitical president that the constitution prescribes. His party needs new leaders untainted by close ties to him and his monarchical ambitions. Because of the opposition’s ineffectiveness, change in Turkey has for some time seemed most likely to come from within AK. Many leading AK figures, including Mr Erdogan’s predecessor as president, Abdullah Gul, have made clear that they dislike his polarising style and authoritarian streak. Indeed, Mr Gul, who as co-founder of the party and a former prime minister has the stature to stand up to Mr Erdogan, could be an excellent candidate for the job again (see article).

The economy and Europe

Whoever is the next prime minister faces some formidable tasks. Civil society needs a period of recuperation after more than a decade of Mr Erdogan’s mauling. In part thanks to the stunning success of the HDP, the Kurdish peace process must be urgently reinvigorated. And the economy needs big reforms to improve competitiveness, ease regulation, cut unemployment, raise labour-force participation and reduce reliance on construction. The central bank, long under attack by Mr Erdogan, should have its independence reaffirmed. Economic growth has recently slumped and the current-account deficit is gaping. Without liberalising reforms soon, the danger of a bust in Turkey is clear—which helps explain why the vulnerable lira fell sharply this week.

The European Union, too, should do more. It was partly because Turkey’s membership talks, begun in 2005, seemed to go nowhere that Mr Erdogan drifted towards autocracy. Now that Turks have so thrillingly demonstrated their democratic credentials, the EU should revive the negotiations. There is also new hope that the age-old Cyprus problem might be solved (see article). Turkey matters hugely for the future of Europe. Resurrecting its aspirations for EU membership would be a fine reward for its admirable voters.