The bill, which prohibits "inappropriate treatment of writings with significant religious importance for a recognised religious community", was passed with 94 votes in favour and 77 opposed in the 179-seat Folketing.
"We must protect the security of Denmark and the Danes. Therefore, it is important that we now have better protection against the systematic insults we have seen for a long time," Justice Minister Peter Hummelgaard said in a statement.
In practical terms, it will be forbidden to burn, tear or otherwise defile holy texts publicly or in videos intended to be disseminated widely.
Those who break the law, which will be evaluated after three years, risk a fine or up to two years in prison.
Over the summer, Denmark and neighbouring Sweden became the focus of anger across several Muslim countries after a slew of protests involving burnings and desecrations of the Koran.
Nearly a thousand protesters attempted to march to the Danish embassy in Baghdad's fortified Green Zone in late July following a call by firebrand cleric Moqtada Sadr.
In response to the worsened security situation, the Scandinavian country temporarily tightened border controls, but returned to normal on August 22.
Between July 21 and October 24 this year, 483 book burnings or flag burnings were recorded in Denmark, according to national police figures.
Criticism
Initially announced at the end of August, the bill was amended following criticism that its first draft limited freedom of expression and would be difficult to enforce.
It was originally planned to cover objects of significant religious importance.
The first draft was also criticised by some -- including politicians, artists, media and freedom of speech experts -- as a return to a blasphemy law that Denmark abolished in 2017.
During a lengthy debate in parliament ahead of the vote, opposition lawmakers railed against the government, accusing it of sacrificing freedom of expression.
"It is a betrayal. A huge failure on the part of the government," Inger Stojberg, leader of far-right Denmark Democrats, told parliament.
In 2006, a wave of anti-Danish anger and violence erupted in the Muslim world following the publication of caricatures of the Prophet Mohammed.
"Imagine that we are becoming the generation that curtailed freedom of speech. I hadn't actually thought this would be -- and certainly not after the Muhammad crisis. Back then, we stood firm," Stojberg said.
In neighbouring Sweden, the government has condemned desecrations of the Koran at protests while upholding the country's constitutionally protected freedom of speech and assembly laws.