The governor was hauled into court last year to face trial on charges of insulting Islam while campaigning for re-election.
Islamic hardliners outside the Jakarta court cheered and shouted "God is greatest!" as news came through that Basuki Tjahaja Purnama was to be sent to prison, a surprisingly harsh punishment after prosecutors recommended only probation.
Purnama, Jakarta's first non-Muslim governor for half a century and its first ethnic Chinese leader, looked calm when the verdict was announced and said he would appeal, as some of his supporters in court burst into tears.
The governor was taken to a Jakarta prison after the verdict but it was unclear whether he would remain in jail or be released later to allow him to file his appeal.
The governor was hauled into court last year to face trial on charges of insulting Islam while campaigning for re-election, in a case critics said was politically motivated.
The trial came after a series of major protests in the capital against the leader, known by his nickname Ahok, that drew hundreds of thousands onto the streets.
His once unassailable opinion poll lead shrank amid the controversy and he lost the race to lead Jakarta last month to a Muslim challenger, a result that fuelled fears Indonesia's moderate brand of Islam is coming under threat from increasingly influential radicals.
The five-judge panel at the Jakarta court found Purnama guilty of blasphemy after a months-long trial.
Announcing the verdict, presiding judge Dwiarso Budi Santiarto said Purnama was "convincingly guilty of committing blasphemy and is sentenced to two years in prison" and ordered him to be detained.
Blasphemy carries a maximum jail term of five years in Indonesia but the verdict was a surprise as judges in the country typically follow the recommendation of prosecutors in criminal cases.
Prosecutors last month urged judges to hand Purnama two years of probation, with a possible one-year jail term if he committed a crime during that period.
Outside the court, hundreds of Islamic radicals wearing white Muslim skullcaps celebrated as they heard about the jail sentence.
"Thank God, he should be jailed -- this is right. He has insulted us," Bachtiar, 38, who like many Indonesians goes by one name, told AFP.
Andreas Harsono, Indonesia researcher for Human Rights Watch, said the decision would damage the country's reputation internationally as a bastion of tolerant Islam.
"It's another big step in the slow decline of religious freedom in Indonesia," he told AFP.
Tobias Basuki, an analyst from Jakarta think-tank the Centre for Strategic and International Studies, said the shock decision could have been driven by pressure from Purnama's political foes on the notoriously corrupt judiciary.
He suggested that Purnama's rivals may have wanted him to be put behind bars straightaway -- which would mean he could no longer serve as governor -- instead of waiting to take over from him when he stands down in October.
The controversy began in September when Purnama, known for his outspoken style, offended Muslims after he quoted a passage from the Koran during his re-election campaign.
He insinuated that his opponents had used a Koranic verse to trick people into voting against him.
An edited version of his speech went viral online, sparking outrage far beyond Jakarta, where Purnama has ruled since his predecessor Joko Widodo became president in late 2014.
Before the blasphemy controversy erupted, Purnama enjoyed a large lead in opinion polls due to his determination to clean up traffic-clogged, polluted Jakarta.
The trial started in December and dragged on for months, with both the prosecution and defence calling more than 40 witnesses.
Purnama's team have accused the prosecution of calling biased witnesses, saying that many were not even present when the alleged blasphemy took place.
Critics want the country's blasphemy laws overhauled. The legislation was rarely used during the 32-year rule of strongman Suharto, but in recent years it has been exploited to persecute minorities, rights groups say.