Image copyright AFP Image caption Mr Purnama denied blasphemy and plans to appeal against his sentence

The outgoing governor of Jakarta has been jailed for two years for blasphemy after judges handed down a sentence that was harsher than expected.

Basuki Tjahaja Purnama, also known as Ahok, was accused of insulting Islam by referring to a verse in the Koran in a campaign speech last year.

Mr Purnama, a Christian in Muslim-majority Indonesia, has denied blasphemy and plans to appeal.

His case was seen as a test of the country's religious tolerance.

Mr Purnama was taken into custody immediately after the verdict was read out. His deputy Djarot Saiful Hidayat will govern Jakarta until the term ends in October.

The sentence was harsher than that requested by prosecutors, which was a one-year suspended sentence.

The governor was "found to have legitimately and convincingly conducted a criminal act of blasphemy, and because of that we have imposed two years of imprisonment", the judge told the court.

The verdict was met with strong protest. Hard-line Islamic groups who called for the maximum penalty of five years said it was too lenient, but Mr Purnama's supporters said it was too harsh and that he should be acquitted.

Protesters from both camps had gathered outside the court, which was guarded by around 15,000 security personnel from the police and military.

Tense face-off - Rebecca Henschke, BBC Indonesian, Jakarta

Image caption Many Ahok supporters were upset after the verdict was read out

Outside the court supporters of Governor Ahok broke down in tears when they heard the verdict. Some hugged each other.

Andi, a devoted Muslim, said she felt heartbroken. "He was such a good man and great leader... He didn't care what religion people were. Now he has been framed," she said.

Many here believe the case against him is politically motivated. But a short distance away, the atmosphere among the governor's critics - a coalition of Islamic groups - was one of anger.

"The sentence is too light, he should have got the maximum of five years, or better still be hung," said Solihin.

Men around him then threw their fists in the air and cried out that God would hand out justice. Riot police closed ranks to make sure both sides did not meet.

The battle is far from over. Governor Ahok will appeal the decision. Islamic groups who oppose him say they will push for a harsher sentence.

Mr Purnama was accused of blasphemy for comments he made during a pre-election speech in September 2016.

He implied that Islamic leaders were trying to trick voters by using a verse in the Koran to argue that Muslims should not vote for a non-Muslim leader.

His remarks, which were widely shared in an edited video, sparked outrage among religious hard-liners. They staged regular large rallies calling for him to face trial.

Throughout the trial, Mr Purnama denied wrongdoing, but did apologise for his comments.

Image copyright EPA Image caption Some protesters were angry at the sentence and felt it was too lenient

Mr Purnama became governor after his predecessor, Joko "Jokowi" Widodo, was elected president in 2014.

As an ethnic Chinese Indonesian and Christian he is a double minority, and was Jakarta's first non-Muslim governor for 50 years.

His political success was also seen as a significant development given the violent anti-Chinese riots that occurred in the city in 1998.

Before the blasphemy allegations, he had been widely hailed as a straight-talking politician with a strong anti-corruption stance.

But the controversy overshadowed scheduled elections last month.

Despite his enduring popularity with many in Jakarta for his efforts to improve living standards, he lost to conservative Muslim candidate Anies Rasyid Baswedan.

Indonesia is the world's most populous Muslim country. About 85% of its population are Muslim, but the country officially respects six religions.