A new law has been passed in Denmark's parliament that makes it illegal to desecrate any holy text in the country, after a recent string of public desecrations of the Koran by a handful of anti-Islam activists sparked angry demonstrations in Muslim countries.

The Scandinavian nation has been viewed abroad as a place that facilitates insults and denigration of the cultures, religions and traditions of other countries.

The purpose of the law was to counter "the systematic mockery" which, among other things, has contributed to intensifying the threat of terrorism in Denmark, the Justice Ministry has said.

The Folketing, or parliament, adopted the law in a 94-77 vote, with eight legislators 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.

During the more than four-hour debate, left-leaning and far-right parties united against the centre-right government, repeatedly demanding 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.

"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, said.

Inger Stojberg, of the anti-immigration Denmark Democrats, said the new law was a capitulation to Islam and a bowing down to countries that "do not share (our) set of values".

"A restriction of freedom of expression is wrong in a modern and enlightened society like the Danish one," Ms Stojberg said.

This year alone, activists have staged more than 500 protests, including burnings of the Koran, in front of embassies of Muslim countries, places of worship and in immigrant neighbourhoods.

Denmark has repeatedly distanced itself from the desecrations, but has insisted that freedom of expression is one of the most important values in Danish society.

The government has said there must "be room for religious criticism" and that there were no plans to reintroduce a blasphemy clause that was repealed in 2017.

In 2006, Denmark was at the centre of widespread anger in the Muslim world after a Danish newspaper posted 12 cartoons of the Prophet Mohammed, including one wearing a bomb as a turban.

Muslims consider images of the prophet to be sacrilegious and encouraging idolatry.

The images escalated into violent anti-Denmark protests by Muslims worldwide.

Those who violate the new law face fines or up to two years in prison.

Before it takes effect, Denmark's figurehead monarch Queen Margrethe needs to formally sign it.

That is expected to happen later this month.