Denmark and Sweden experienced a series of public protests this year where anti-Islam activists burned or otherwise damaged copies of the Koran, triggering demands that the Nordic governments ban the practice.
According to Justice Minister Peter Hummelgaard, more than 500 demonstrations that included burnings of the Koran or flags were registered since July.
"Such demonstrations can hurt Denmark's relations to other nations, our interests and ultimately our safety," Hummelgaard said.
Denmark has 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," said Inger Stojberg, leader of the anti-immigration Denmark Democrats party. "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."
Denmark's centrist coalition government has argued that the new rules will have only a marginal impact on free speech and that criticising religion in other ways remains legal.
The vote followed a five-hour debate in parliament and 94 members voted in favour, 77 against.
Breaking the new law will be punishable by fines or up to two years in prison, the government has said.
Sweden is also considering how to prevent burning of the Koran but is looking at whether police should factor in national security when deciding on protest applications rather than a ban.
(Reporting by Louise Breusch Rasmussen, Anna Ringstrom, Ilze Filks, additional reporting by Jacob Gronholt-Pedersen, editing by Terje Solsvik, Alexandra Hudson)
Rasmus Paludan, leader of Danish far-right anti-Islam party Stram Kurs (Hard Line), burns a copy of the Koran in front of the Turkish embassy in Copenhagen, Denmark, 27 January 2023. The action was met with outrage and protests around the world since Paludan burned a copy of the Muslim holy book in Stockholm a week earlier. EPA-EFE/Olafur Steinar Gestsson