JAKARTA, Indonesia—Islamic hard-liners scored a victory Tuesday in the world’s largest Muslim-majority country, as a court handed an unexpectedly harsh two-year prison sentence to the capital’s Christian governor for blasphemy.

The sentence for Jakarta Gov. Basuki Tjahaja Purnama, a close ally of President Joko Widodo, signaled that his defeat in an election last month didn’t end tensions simmering in the Southeast Asian country since mass protests against him more than six months ago—the biggest in the capital in decades....