VICTORY for Turkey’s Recep Tayyip Erdogan and his Justice and Development (AK) party in presidential and parliamentary elections on June 24th should have been a foregone conclusion. The strongman enjoys unwavering support from his religious base, indirect control over practically all big news outlets, and emergency powers that allow him to rule by decree, lock up some critics and make others think twice before speaking.

The second-largest opposition party in parliament, the pro-Kurdish People’s Democratic Party (HDP), has been in effect banished from the airwaves. Its candidate for president, one of Mr Erdogan’s most outspoken rivals, Selahattin Demirtas, was arrested in 2016 on trumped-up terrorism charges, and is leading his campaign from a prison cell.

The president’s opponents are still the underdogs in the coming votes, to be held early and for the first time simultaneously. But they seem to have picked up momentum—and found the right candidates. Muharrem Ince, the nominee of the Republican People’s Party (CHP), is a popular firebrand and one of the few secular politicians capable of connecting with religious voters. Born into a conservative family, Mr Ince prays regularly and defends the right of female civil servants to wear the Islamic headscarf, but also seems to enjoy an occasional drink. Meral Aksener, a veteran nationalist and a former minister of the interior, has propelled herself and her Iyi (“Good”) party from obscurity to the national stage. Remarkably for a party founded less than a year ago, Iyi seems poised to receive well above 10% of the vote in the parliamentary election. Recent polls give Mrs Aksener herself up to 20% in the first round of the presidential contest. Mr Demirtas has also polled in the double digits—not bad for a politician forced to communicate with the outside world through his lawyers and a few social-media accounts.

Mr Erdogan’s opponents have taken a few pages out of the president’s playbook. Earlier this year AK formed an electoral coalition with the right-wing Nationalist Movement Party (MHP), whose leader spent years calling Mr Erdogan a dictator only to change tack in exchange for help fighting off an internal challenge. By hitching its wagon to the ruling party’s, the MHP will no longer have to clear the 10% threshold needed to enter parliament.

The opposition has responded in kind. Soon after Mr Erdogan called early elections, the CHP, Iyi, the Felicity Party (SP) and the small Democrat Party forged an alliance of their own, paving the way for even the smallest of the group to send a few members to parliament. A surprising display of solidarity followed. When rumours started to fly that Iyi might be barred from running in the elections due to a controversy about the timing of its party congress, the CHP loaned it some of its own MPs. (Any party with at least 20 members of parliament can take part in the elections.) Each of the two main opposition hopefuls has promised to endorse the other in the second round against Mr Erdogan, assuming he does not win outright.

The opposition has been less magnanimous towards the HDP, which was not invited to join the alliance. Most Turks view the party as a front for the PKK, a Kurdish insurgent group. But some overtures have been made. The presidential contenders have all called for Mr Demirtas to be released before the elections, a plea the courts and the government have ignored.

The sight of the CHP, a secularist party, in cahoots with the SP, an Islamist one, probably has their respective founders, Kemal Ataturk, the father of modern Turkey, and Necmettin Erbakan, a former prime minister, turning in their graves. But desperate times make for desperate bedfellows. Temel Karamollaoglu, the SP’s leader, says the alliance is a marriage of necessity designed to rescue what remains of Turkey’s democracy from Mr Erdogan’s grip. The president and his men have less in common with political Islam than with crony capitalism, says Mr Karamollaoglu. “There is no justice,” he says. “The separation of powers is gone.”

The opposition parties have vowed to scrap Mr Erdogan’s new constitution, which passed by a sliver in a 2017 referendum marred by irregularities and allegations of fraud. The changes will kick in immediately after the elections, reducing parliamentary oversight, abolishing the office of prime minister and concentrating all executive power in the hands of the president. Mr Ince describes this as a recipe for a “one-man regime” and promises to change the constitution again to return to parliamentary rule “as soon as possible”. He and others also pledge to end the state of emergency, which began days after an abortive coup in July 2016, and which has served as cover for sweeping government repression. They may be able to do this, if they can win enough seats to wrest control of parliament from the AK.

For now, Mr Erdogan’s biggest headache is a currency crisis largely of his own making. The president has long insisted on holding lending rates down to keep the economy firing on all cylinders. The central bank has obliged. But the resulting credit binge has come at a cost. The value of the Turkish lira has fallen by half against the dollar since 2015. Following an interview in May in which Mr Erdogan repeated his odd view that high interest rates cause inflation and signalled he would take even greater control of monetary policy after the elections, the currency lost 10% of its value in a week. It strengthened only when Mr Erdogan ceded to orthodoxy and allowed the central bank to raise rates (see article). Turkish companies that racked up mountains of foreign debt may now be on the verge of default. Despite his authoritarian record and wacky economic theories, the markets have always preferred Mr Erdogan and his AK to the fragmented opposition. Over the past month they may have had a change of heart.