Jakarta’s outgoing ethnic Chinese, Christian governor Basuki “Ahok” Purnama was sentenced to two years in jail on Tuesday for blasphemy against Islam, upending expectations that he would be handed a lighter sentence as the contentious trial threatens social harmony in the world’s largest Muslim-majority nation.

The north Jakarta district court ruled that Purnama, 50, was guilty of insulting Islam in a campaign speech to rural residents last September. The penalty imposed was far harsher than the probationary sentence recommended by prosecutors. The five-person panel of judges ordered the immediate arrest of Purnama, commonly known by his Chinese nickname Ahok. The governor said he would appeal the verdict, but prosecutors elected to send him to the high-security Cipinang prison after the court hearing ended at around 11am local time. He was undergoing a medical examination in the afternoon.

Jakarta’s ethnic Chinese leader is gone, is Widodo next?

Purnama was found to have “legitimately and convincingly conducted a criminal act of blasphemy,” the head judge Dwiarso Budi Santiarto told a packed courtroom. The judges dismissed the defence argument that the case was politically motivated. Thousands of Purnama’s supporters had gathered outside the court venue from the wee hours of Tuesday, and television images showed some sobbing after the verdict was delivered.

At the same venue, anti-Purnama groups broke into cheers after the outcome was announced. The hearing was held inside an auditorium in the agriculture ministry building instead of the court’s original location for security reasons, officials said.

Political observers said the decision would impact social harmony in the country, which is still recovering from the wounds of communal riots in 1997 in which the ethnic Chinese minority was targeted.

The case, pitting an ethnic Chinese Christian against Islam, the religion practised by 90 per cent of the country, is seen by observers as the key reason for Purnama’s defeat in last month’s gubernatorial election in the national capital. The eventual winner Anies Baswedan was backed by Islamist hardliners such as the Front Pembela Islam (FPI) group which lobbied the government to press charges against Purnama.

One exit poll conducted on election day on April 19 showed 30.1 per cent of the electorate voted against Purnama despite expressing satisfaction for his performance in office. Of this, 73.5 per cent said they believed the governor was guilty of blasphemy.

“Politicisation of religion [has] taken another low never thought possible. The blasphemy sentencing against Ahok is a complete farce,” Tobias Basuki, a Jakarta-based political analyst, wrote on Twitter minutes after the verdict.

Purnama took over as Jakarta’s governor in 2014 without elections as then-incumbent Joko Widodo became president. Purnama was then the deputy governor. Known for a no-nonsense style and work ethic, Purnama enjoyed high approval ratings in the national capital until the controversy broke last year.

In comments to voters of the Thousand Island regency in September, Purnama had said Muslim leaders were wilfully misinterpreting a verse in the Koran in order to make Muslims abandon their support for him. He later apologised for the off-the-cuff remark – but said he had no intention of insulting Islam. Prosecutors brought formal charges two months later amid mass protests organised by hardline Islamists including the FPI.

WATCH: Jakarta rally turns violent as Muslim hardliners attack police

Some 13,000 police officers were deployed across Jakarta on Tuesday morning amid fears that violence would break out

President Joko Widodo had earlier urged restraint over the trial and asked all sides to respect the court’s decision. In an interview with This Week in Asia last month, the president said he was confident the country would “come together and... live in unity” after the polarising gubernatorial election. Analysts however say the election result and the ensuing communal tensions are a major blow to Widodo ahead of presidential elections in 2019.

The incoming Jakarta governor is an ally of opposition leader Prabowo Subianto, a former general aligned with leading hardline Islamic groups. In 2014 Widodo appointed the 47-year-old Baswedan as education minister when he came to power, but sacked him last year in a cabinet reshuffle.