THE mood in Jakarta was jittery in the days leading up to its gubernatorial election on April 19th. Around 64,000 police, soldiers and other security personnel were deployed to keep the peace. At least one policeman guarded every one of the 13,000-odd polling stations.

Islamist agitators implied the incumbent governor, Basuki Tjahaja Purnama, known as Ahok, was planning to steal the election, and threatened to flood the city with supporters to safeguard the vote. They accused Ahok, who is both Christian and of Chinese ancestry, of “Christianising” Jakarta because, to some paranoid minds, a mosque built by the city government resembles a cross. A Facebook user claimed the gang rape and murder of Ahok’s supporters would not be sinful.

Anxious ethnic-Chinese, in turn, shared posts warning that the election of Ahok’s rival, Anies Baswedan, would lead to the forcible imposition of Islamic law. “People are saying, ‘Behave yourself, or we’ll make another May 1998,’” said one Chinese Christian Jakartan—referring to the month when deadly pogroms against Chinese broke out across the city.

The head of Nahdlatul Ulama, Indonesia’s biggest Muslim social organisation, with 60m members, appeared hand-in-hand with leaders of Indonesia’s five other officially recognised faiths to appeal for unity and peace. Joko Widodo, Indonesia’s president, universally known as Jokowi, voiced support for “the principle of live and let live, as well as unity in diversity” (the latter phrase being Indonesia’s national motto). Banners urging “A safe and peaceful election” and proclaiming “We are all brothers” flapped above intersections all around the city.

In the end, the election passed off peacefully. Unofficial counts showed Mr Baswedan, Jokowi’s former minister for education, easily beat Ahok, with around 58% of the vote—a far wider margin of victory than opinion polls had predicted. Ahok had won an automatic promotion from vice-governor to governor when Jokowi, his predecessor, was elected president. He would have been the first Chinese Christian to win the job in an election. In the end, however, a row about religion upended his campaign.

Ahok had been popular, having waged war on Jakarta’s corrupt and idle bureaucrats and laboured manfully to improve its infrastructure. His election seemed secure. But early in the campaign he gave a speech in which he urged voters not to heed those who used a particular verse from the Koran to argue that Muslims should not vote for Christians. Hardline Islamists, who had attacked Ahok for his race and religion since he became governor in 2014, edited the speech to make it sound as if he was criticising the Koran. The doctored video, disseminated widely on social media, succeeded in creating the desired uproar.

The agitators organised massive anti-Ahok rallies. In November prosecutors charged Ahok with blasphemy. The charge may be tendentious, but the potential penalty is severe: up to five years in prison. For nearly six months Ahok has spent every Tuesday in court, with conviction a genuine threat: very few of those charged with blasphemy are acquitted.

Mr Baswedan, a politician as slippery and accommodating as Ahok is blunt and forceful, spied an opening. On January 1st he spoke at the headquarters of the thuggish Islam Defenders Front (FPI), a vigilante group. Mr Baswedan denies pandering to radicals: he says he visited just to “answer questions”, and to quell rumours that he is a Shia (most Indonesian Muslims are Sunni; Shias have been prosecuted as “deviants”). But he said nothing to counter FPI’s vituperative attacks on Ahok, and later joined its rabble-rousing leader, Rizieq Shihab, for prayers before a big anti-Ahok rally. The iconography of Mr Baswedan’s campaign was also clear: throughout the campaign he sported a black peci—a cap worn by pious Javanese.

In the wake of his victory, Mr Baswedan made all the right noises, pledging to defend diversity. But he celebrated in the company of Mr Shihab, once again. His victory undoubtedly strengthens the hardliners who backed him. Marcus Mietzner of the Australian National University worries that the chauvinists have demonstrated “the capacity to shift a small but decisive segment of swing voters their way.” What is more, he adds, “it demonstrates that militant Islamists have become more organised, established better connections with…elite networks, and have found ways of building alliances with mainstream politicians.”

That will alarm Jokowi. Mr Baswedan had the backing of Prabowo Subianto, whom Jokowi defeated in 2014 and who is widely expected to challenge him again at the next presidential election, in 2019. Sandiaga Uno, Mr Baswedan’s running-mate, says Mr Prabowo insisted that he and Mr Baswedan sign “a binding agreement” to stay in their new jobs for a full term, in effect excluding them from the next presidential election. But the governorship was a springboard to the presidency for Jokowi, and Mr Prabowo may yet tap one of the pair as his running-mate.

Mr Baswedan is not about to impose Islamic law in Jakarta. But hardline forces certainly helped him win. That genie is not easily returned to the bottle.