Danish lawmakers have repealed a 334-year-old blasphemy law that forbids public insults of a religion, such as the burning of holy books.

Only a handful of blasphemy trials have taken place in the past 80 years, and several high-profile cases have been dropped, including one involving a caricature of the prophet Muhammad published in the Jyllands-Posten newspaper in 2005.

Denmark was the only Scandinavian country with a blasphemy law, which called for up to four months in prison upon conviction, although most people were fined instead.

Politicians who wanted to repeal the law introduced in 1683 “do not believe that there should be special rules protecting religions against expressions”, the Danish parliament said on its website.

But remarks and acts that threaten or demean certain groups of people because of their religious beliefs will still be punishable.

“Religion should not dictate what is allowed and what is forbidden to say publicly,” Bruno Jerup, an MP who proposed to repeal the law, was quoted as saying by Jyllands-Posten. “It gives religion a totally unfair priority in society.”

A Danish man who filmed himself burning the Koran before posting a video of his act on Facebook in 2015 would have faced a blasphemy trial next week, but the case was dropped after the law was revoked.

In 1946, two people were fined for conducting a baptism during a masked ball, and in 1971, two public radio officials were convicted for broadcasting a song about a woman’s sexuality and her refusal of any divine moral figure.