On March 22, in a working-class neighborhood on Istanbul’s Asian shore, several thousand people gathered around a bus. They held up Turkish flags, or else banners printed with six white arrows and the letters CHP, the insignia of the secular opposition party. Most everyone joined in chanting, “Everywhere is bribery; everywhere is corruption.” It was an echo of last year’s Gezi Park protests — “Everywhere is Taksim; everywhere is resistance” — but here it sounded nostalgic, not defiant. The government had just blacked out Twitter. Gezi seemed suddenly deep in the past.

A metal platform had been welded onto the roof of the bus, and Mustafa Sarigül, the CHP’s candidate for mayor in the March 30 elections, was standing on it. After the usual promises to be “a mayor of the people,” Sarigül turned his attention to what he believed the Istanbul race was really about: the fight against Prime Minister Recep Tayyip Erdogan.

Sarigül’s grievances with Erdogan and his Islamist Justice and Development Party (AKP) were not only political. In January, Sarigül had found his assets frozen by the state, ostensibly for having failed to pay back a sixteen-year-old loan, but actually, he suspected, for having decided to run for mayor. “Can you imagine all the things they’re doing to me?” he asked the crowd, working himself into a rage. Sarigül’s political persona, like Erdogan’s, is a mix of paternal drill-sergeant and avuncular storyteller. At an earlier event, I’d watched him yell at a teenager for smoking a cigarette.

When the rally ended, we climbed inside the bus, where I found a seat in a small room at the back, squeezed between two advisers and opposite a German TV crew. Sarigül seemed to believe that the Germans’ presence was a sure sign of his impending victory. “Why else would they be here?” he’d asked at an earlier rally.

When I inquired about Kadir Topbas, his opponent and the incumbent AKP mayor, Sarigül sneered. Topbas, he said, had practically declined to show up. “He’s not in the city squares, he doesn’t hold rallies, he doesn’t answer the questions I ask.” Topbas had not needed to campaign, because “the only man running in Istanbul,” Sarigul said, was the prime minister.

One would think that the man at the helm of a country that aspires to dominance in the Middle East and the Muslim world has enough on his plate without adding a mayoral campaign. Even in his twelfth year as prime minister, however, it’s hard to shake the impression that Erdogan, who grew up in Istanbul and served as its mayor in the mid-1990s, is moonlighting at his old job.

After a decade-long boom, Istanbul, home to 14 million people, has transformed into a vast construction site. Under Erdogan’s watchful eye, certain neighborhoods have flourished. The city boasts new metro lines, new roads, and, as of last fall, the world’s first undersea rail tunnel linking two continents. Yet the construction frenzy has come at a cost. To make way for new shopping malls and flashy housing complexes, a number of historic neighborhoods have been razed, their poorer tenants priced out, evicted, and forced to the fringes. A creeping wave of cement has deprived whole neighborhoods of green space. Concerns about a housing bubble are getting louder. By some estimates, Istanbul is home to about one million unsold apartments.

Erdogan, meanwhile, appears determined to convert the rest of the city into a showcase for his imperial ambitions. A new bridge, its construction coming at the expense of more than two million felled trees, is rising over the Bosporus Strait. A mega-mosque capable of accommodating forty thousand people is in the works. A forested area equal in size to roughly twenty Central Parks has been set aside to house a new international airport. By 2023, the centenary of the Turkish Republic, Erdogan plans to have launched the most controversial and unrealistic of his schemes, a thirty-mile-long canal linking the Black and Marmara Seas.

Many of these projects, as well as links between the building sector and Erdogan’s administration, have lately come under increasing scrutiny. Since mid-December, a sweeping probe has ensnared several top officials and some of Turkey’s biggest construction tycoons, and has exposed compelling evidence of favoritism, rigged tenders, and kickbacks to top state officials, including the prime minister himself.

Branding the investigation a “judicial coup” against his government, Erdogan has removed the prosecutors involved, reshuffled more than 7,000 police officers, and brought the country’s top judicial body to heel. Across several weeks, undeterred by claims of a cover-up, he has practically defanged the investigation. But its fallout continues to haunt him.

For the past three months, leaked documents and wiretapped conversations from the highest levels of government have found their way online, revealing an impressive variety of sleaze. In one audio recording, which Erdogan called a “shameless montage,” he and his son appear to discuss removing millions of dollars in cash from their homes. In another, AKP heavyweights are heard cutting crooked deals with property developers. Most relevant to the March 30 election in Istanbul was a leaked tape in which Erdogan is heard ordering a TV executive to give Sarigül less media coverage.

The day after I met Sarigül, with exactly a week to go before the election, Erdogan held an event of his own. It was advertised, in 1930s fashion, as “The Rally for the National Will.” The event was being held in a huge public square that had been constructed under AKP leadership as part of a land reclamation project. The urban theorist Jean-François Pérouse recently called the square Istanbul’s “giant vomit onto the Marmara Sea.”

By the early afternoon, it teemed with over a million people. Volunteers lobbed plastic water bottles and sandwiches into the crowd. To get a better view of the stage and escape the crush of bodies, dozens of men had climbed a row of newly planted trees separating the gathering area from the neighboring road. Near the spot where I stood, an elderly woman, having fainted, was being carried off on a stretcher.

While we awaited the speeches, I chatted with Hakan Temur, a soft-spoken forty-one-year-old shopkeeper who had brought along his teenaged daughter. He supported Erdogan, he said, partly because his ban on alcohol sales after 10 p.m. “has made the streets safe.” When I asked him about the leaked recordings, he dismissed them as a “smear campaign.” “[Erdogan] has become the victim of a global conspiracy,” he said.

“The world’s never seen a leader like Erdogan,” said Ayse Yüksel, a beautician in her late thirties. “Where there were no roads, he built roads. Where there was no electricity, there’s electricity. Where there was no water . . . ” She went on for a while. “Allah sent him to us,” I heard her say when I tuned back in. “He’s tireless, he’s always working, he’s sleeping three hours a day. For that kind of work, not even half a million lira [$250,000] a month is enough.”

I went to try to find someone who actually cared about the graft allegations, to little avail. “I don’t support corruption,” said a young housewife named Ayse Bayram, “but I’d support [Erdogan] even if the claims turned out to be real. Because of all the things he’s done for the country, he has every right.” A January poll had proved her opinion to be prevalent. Seventy-seven percent of Turks believed that government ministers had accepted bribes, but 47 percent were still prepared to vote AKP.

Yasar Yakis, a former foreign minister for the AKP, once explained to me that Erdogan’s religious electorate loved him mainly for being one of them. Pious, conservative people, he said, remained enamored with the prime minister. “He has protected their way of life, their religion, their right to wear the [Islamic] headscarf in public.”

After what seemed like hours of pep talks and anthems, the official part of the seaside rally finally got under way. Kadir Topbas, the incumbent mayor, spoke for fewer than five minutes. “The work we’ve done in Istanbul speaks for itself,” he said, to lukewarm applause. Then Erdogan, having arrived by helicopter, took the stage. He riffed for nearly two hours. He offered a poem, an anecdote about his encounter with an elderly voter, an ode to Istanbul, and, as a climax, excoriations of the media, the opposition, Twitter (which he had banned three days earlier), YouTube (which he would ban four days later), and Facebook (which was said to be next). The crowd loved it.

He closed, as usual, with a parting shot at his recently appointed archenemy, the Islamic sect known as the Gülen movement, which he and most outside observers believe to be the force behind the corruption accusations and the leaks. “Leeches are more virtuous,” he boomed, towering over the crowds, now, from a platform adjacent to the stage. “Leeches suck dirty blood, but they suck clean blood.”

The line was a huge crowd-pleaser. “If it comes to war, we will fight for him,” said Suat, a textile worker who’d come to the rally with several friends. “It’s in our blood. We are the grandsons of the Ottomans.”

In nearly every appearance since last summer’s Gezi Park protests, Erdogan has challenged his opponents and critics — including the CHP, the Gülenists, and anyone else concerned with his authoritarian bent — to try to better him in an election. Today, faced with blowback from the latest corruption scandal, Erdogan has appointed the ballot box as his lawyer, prosecutor, jury, and judge. If the AKP wins Istanbul’s mayoral election and other local races across the country, and especially if it wins big, he has implied, he will have been absolved of all wrongdoing. Perversely, he could be right. Armed with a resounding victory, Erdogan may hold on to power for years to come, whether by rewriting party rules and making himself eligible for a fourth term as prime minister, or by running in the presidential elections later this summer.

A poor nationwide showing will have the opposite impact. If the party receives well below 40 percent of the total vote, Asli Aydintasbas, a columnist at the daily newspaper Milliyet, told me, Erdogan’s political future will be in jeopardy. Early parliamentary elections might beckon, she said, and, sooner rather than later, “the investigations will catch up with him and his family.”

On the CHP’s campaign bus, Sarigül had been just as clear about what was at stake on March 30, particularly in Turkey’s biggest city. Istanbul, he said, would make or break Erdogan. Most polls showed him trailing Kadir Topbas by a few points, but he was confident of a win. If he were to deliver one, he said, swallowing a handful of peanuts, “Tayyip’s days would be counted.”

As of Sunday night, it was clear that they weren’t, at least not just yet. With most ballots counted, the AKP was winning cities across Turkey and on pace to secure about 45 percent of the vote nationwide. Sarigül was trailing by almost ten points.

Piotr Zalewski is an Istanbul-based freelance writer for Time, Foreign Policy, and the Financial Times, among others. Follow him on Twitter: @p_zalewski.