JAKARTA, Indonesia — On a blisteringly hot day a few months ago, I joined a crowd of worshipers at Jakarta’s Istiqlal Mosque, the largest mosque in Southeast Asia, seating about 200,000. After Indonesia secured its independence from the Netherlands in 1949, the looming modernist building was envisioned as a monument to the country's extraordinary religious diversity: Istiqlal was designed by a Christian architect and is directly across from Jakarta Cathedral.

As I arrived, Abdullah Gymnastiar, a Muslim televangelist, began his sermon. When he congratulated London for selecting Sadiq Khan, a Muslim, as mayor, I thought I was settling into the type of preaching that gives Indonesia — which has more Muslims than any other country, but also influential Christian, Buddhist and Hindu minorities — its reputation as a land of tolerant Islam.

Only that’s not what I got. Gymnastiar, who is known as Aa Gym, noted the irony that London, a majority-non-Muslim city, had selected a Muslim mayor, while Jakarta, one of the world’s largest Muslim-majority cities, was being led by Basuki “Ahok” Purnama, a Christian of Chinese descent. He said many people found a lot to admire in Ahok, especially his war against incompetence and corruption in the city’s bureaucracy. Nonetheless, Aa Gym said, he could never vote for Ahok in this month's gubernatorial elections. Why not? “Because my ID says I’m from Bandung, not Jakarta,” he said, referring to a different city. He laughed, as did the audience.

No one can deny that Aa Gym gives a good sermon. But then he got serious. The reason he couldn’t vote for Ahok was that the Koran commands Muslims to have Muslim leaders, Aa Gym said — and as a Muslim, he could never vote for a Christian leader. He advised those listening to follow his example.

On Wednesday, the citizens of Jakarta go to the polls in an election that will be an important referendum on tolerance in Indonesia. Ahok, who assumed the governor's job about two years ago when his predecessor, Joko “Jokowi” Widodo, became president, has risen higher than any other ethnic Chinese Christian politician since Indonesia transitioned to democracy in 1998. But ultratraditional Muslims have resisted him from the start of his term and turned out in force to protest his inauguration.

Ever since Ahok advised Jakartans late last year to disregard teachings derived from the Koran that suggest Christians should not lead Muslims, more moderate Muslims have turned on him, too, viewing it as arrogant for him to comment on their religion. Hard-line groups drummed up anger against him. After huge protests against Ahok rocked Jakarta, authorities began prosecuting the governor on blasphemy charges. If convicted in March, he could be sent to prison for up to five years, regardless of whether he wins Wednesday's election.

Both of Ahok’s opponents in the election have emphasized their Muslim identity in a bid to unseat the governor. Although he is a far-from-perfect candidate and is criticized for his eviction of slum dwellers, the race for governor has hinged on Ahok’s identity rather than policies. Most voters still see him as highly effective, but polls suggests it's unlikely that he’ll receive the 51 percent he needs to triumph in a three-way race. Assuming he doesn’t get a clear majority, there will be a runoff in April.

The election is “a point, a very important point, in the decline of religious freedom in Indonesia,” said Andreas Harsono, Human Rights Watch’s representative in Indonesia. “It’s an important test.”