Denmark and Sweden experienced a series of public protests this year where anti-Islam activists burned or otherwise damaged copies of the Koran, sparking tensions with Muslims and triggering demands that the Nordic governments ban the practice.
Denmark sought to strike a balance between constitutionally protected freedom of speech, including the right to criticise religion, and national security amid fears that Koran burnings would trigger attacks by Islamists.
Domestic critics in Sweden and Denmark have argued that any limitations on criticising religion, including by burning Korans, undermine hard-fought liberal freedoms in the region.
"History will judge us harshly for this, and with good reason... What it all comes down to is whether a restriction on freedom of speech is determined by us, or whether it is dictated from the outside," said Inger Stojberg, leader of the anti-immigration Denmark Democrats party, who opposed the ban.
Denmark's parliament adopted the law in a 94-77 vote, with eight MPs absent.
The new legislation will make it a crime "to inappropriately treat, publicly or with the intention of dissemination in a wider circle, a writing with significant religious significance for a religious community or an object that appears as such".
Works of art where "a minor part" includes a desecration but is part of a larger artistic production is not covered by the ban.
"Does Iran change its legislation because Denmark feels offended by something an Iranian could do? Does Pakistan? Does Saudi Arabia? The answer is no," Karina Lorentzen of the Socialist People's Party asked rhetorically.
Denmark's centrist coalition government under Prime Minister Mette Frederiksen has argued that the new rules will have only a marginal impact on free speech and that criticising religion in other ways remains legal.
During the more than four-hour debate on Thursday, parties not part of the government repeatedly demanded that the three-party coalition that presented the draft on August 25 take part in the discussion.
The government did not say anything and were called "cowards" by the opposition.
Breaking the new law would be punishable by fines or up to two years in prison, the government has said.
Sweden, too, is considering ways to legally limit Koran desecrations but is taking a different approach than Denmark.
It is looking into whether police should factor in national security when deciding on applications for public protests.
with AP