ON A rainy Sunday evening Turkey’s prime minister, Recep Tayyip Erdogan, was delivering a fiery speech full of references to the glories of Islam and Turkey’s Ottoman past when a woman on a stretcher was lifted to the podium. He knelt down, took her hand and offered comfort. “Allahu akbar [Allah is great],” she screamed. A sea of supporters, waving Palestinian and Turkish flags, went wild. These scenes at a recent rally in Istanbul have been repeated across Turkey as Mr Erdogan campaigns to become the country’s first popularly elected president.

Few doubt that Mr Erdogan will achieve his goal in a first round of balloting on August 10th. Opinion polls suggest that if turnout is below 80%, he will win up to 55% of the vote and a run-off scheduled on August 24th will be unnecessary. Ekmeleddin Ihsanoglu, a former secretary-general of the Jeddah-based Islamic Co-operation Organisation—who was fielded jointly by the main opposition Republican People’s Party (CHP) and the Nationalists in the hope that he would draw pious voters from Mr Erdogan—is trailing at around 38%. Selahattin Demirtas, the Kurds’ candidate, whose youthful good looks, sharp wit and all-embracing message are appealing even to Kemalist stalwarts, is nonetheless unlikely to attract more than 10%.

Mr Erdogan’s enduring popularity since his conservative Justice and Development (AK) party was catapulted to power in 2002 may seem baffling. A probe, launched in December and targeting his family, cabinet members and business cronies, has thrown up allegations of graft, kickbacks and money-laundering. Mr Erdogan denies any wrongdoing. In March 301 workers perished in a mine explosion in the town of Soma, a disaster widely believed to have been caused by lax safety rules. When heckled by protesters at the scene, Mr Erdogan was filmed cuffing a worker. One of his advisers was caught on camera kicking a protester while security guards pinned him to the ground.

Adding to the government’s blunders, for more than two months Islamic State militants in Iraq have been holding 49 members of the Turkish consulate in Mosul, including the consul-general, as human shields against possible Western intervention. Had Turkey heeded warnings from the Iraqi Kurds to evacuate the consulate before the group overran Mosul, the hostages would probably have escaped.

“There is no mystery to Erdogan’s success,” argues Seyfettin Gursel of Istanbul’s Bahcesehir University. “It’s because of the economy.” Over the past decade millions of Turks have been lifted out of poverty. When the financial crisis hit Europe, Turkey’s economy, fuelled mainly by domestic consumption, kept expanding; growth was over 9% in 2010. Shiny new hospitals, in which the needy receive free treatment, have bolstered a sense of stability and well-being.

Where Mr Erdogan’s critics see a tyrant (he has muzzled the press, stacked the judiciary and the security services with loyalists and rewritten laws to suppress the corruption probe), his supporters see a steadying hand. The former footballer has declawed the army and eased bans on the Islamic-style headscarf. He was the first to negotiate with the Kurds. Before winning a third term in 2011, Mr Erdogan did more than any of his perpetually squabbling, secular-minded predecessors to make Turkey a richer, freer and happier place.

But Mr Erdogan has become increasingly autocratic. He is also a master manipulator. When mass protests erupted last year over government plans to build a shopping mall in Istanbul’s main Taksim Square, Mr Erdogan convinced his base that these were orchestrated by a cabal of Jews and their allies in the media (including The Economist). When the graft scandals erupted in December, he blamed them on Fethullah Gulen, a Pennsylvania-based Sunni Muslim cleric who, he claims, is part of a global conspiracy to overthrow AK. Dozens of alleged Gulenists in the police force have been arrested.

The AK leader’s next goal is to boost the powers of the presidency so that he can continue to rule Turkey from the Cankaya palace. In a draft bill AK deputies proposed, among other things, that the president be allowed to dissolve parliament and to appoint cabinet ministers. “These are powers a Latin American dictator couldn’t dream of,” says Riza Turmen, a CHP deputy.

Nuray Mert, one of dozens of newspaper columnists sacked under government pressure, insists that Mr Erdogan wants to impose a “Saddam Hussein-style Baathist regime”. Gigantic portraits of Mr Erdogan have become ubiquitous. Mr Ihsanoglu and Mr Demirtas were given only a fraction of the airtime granted to Mr Erdogan on state-run television. Oy ve Otesi, an independent election-monitoring group, is already warning of possible fraud.

For now AK lacks the two-thirds majority in parliament needed for the constitutional tweaks to increase the president’s powers. Critically, the economy is beginning to wobble. Inflation is up; growth is down, to around 4%. Exports are slipping because of the violence that has engulfed Syria and Iraq, Turkey’s second-biggest market. Mr Erdogan may well be tempted to call early elections (via the AK puppet prime minister he is hoping to install) before the effects set in. But AK may well not bag enough seats to allow him to fulfil his dreams. He would then turn to the Kurds for their backing in exchange for further political concessions. If that were not forthcoming, Mr Erdogan’s grip may finally weaken, paving the way for a new leader. Many think that would be the best outcome for Turkey.