The headteacher and another staff member at the Hijla High School in the town of Chitalmari were found guilty of "hurting the religious sentiments" of Muslim students and their parents.
The comments sparked protests by students, most of whom are Muslim, and angry villagers descended on the school seeking to beat up the teachers before being stopped by police.
Gay rights activist among two hacked to death in Bangladesh
"They have made abusive comments about Islam and the Prophet Mohammed during a class session," said magistrate Anwar Parvez, who handed down the verdict Monday after the teachers pleaded guilty.
"Local people attacked the school. They wanted to beat the two Hindu teachers," Parvez told AFP.
Criticism of Islam is taboo in the majority-Sunni Muslim nation.
The convictions come as concern mounts over extremism in conservative Bangladesh, which is reeling after a spate of murders of minorities and secular activists.
In recent years, suspected homegrown militants have targeted secular activists and writers who have criticised Islam and radical Muslims.
Bangladesh's top blogger gets death threat
On Monday two gay rights activists were hacked to death in attacks by suspected militants.
Two days earlier a liberal professor was murdered in a northwestern city, a killing claimed by Islamic State militants.
A long-running political crisis in Bangladesh has radicalised opponents of the government and analysts say extremists pose a growing danger.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ