Denmark's parliament has banned the "inappropriate treatment" of religious texts - with a bill widely known in the country as the Quran law.
Offenders now face a fine or up to two years in jail after a 94-77 vote.
It follows a series of burnings of Islam's holy book that led to uproar in Muslim countries.
Denmark and neighbouring Sweden have recently seen a number of street protests over such incidents, raising security concerns in Scandinavia.
During Thursday's heated debates in Denmark's 179-strong parliament, the Folketing, many opposition MPs argued against the bill.
"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," Inger Stojberg, leader of the Denmark Democrats, was quoted as saying by Reuters news agency.
But the country's centre-right coalition government of Prime Minister Mette Frederiksen argued that criticising religion would remain legal, as the bill would only have a marginal impact.
Back in August, when the government was proposing the changes, ministers said they wanted to send a signal to the world after witnessing over a few weeks 170 demonstrations, including Quran burnings in front of foreign embassies.
At the time, Denmark's PET intelligence service warned that such incidents had increased the terrorist threat.
Sweden has also seen a series of Quran burnings, and its security service has warned of a worsening security situation. In July, the Swedish embassy in Iraq was set alight by protesters.
The government in Stockholm is currently considering a similar bill.
Both Denmark and Sweden have abolished blasphemy laws.