Although the official demonstrations on Saturday ended peacefully, police later arrested between 100 and 150 left-wing activists after they started throwing stones at officers.
Both far-left and extreme-right marches took place in Hilleroed, 30km northeast of Copenhagen.
The left-wing marchers, many of them clad in black and bearing banners urging people to "Crush the Nazis", were protesting against an anti-Muslim march by the extreme-right Danish Front.
Daniel Savi, a local secretary of the youth wing of the Socialist People's party, which organised the left-wing march, told AFP: "We say no to the racist and ignorant Danish Front demonstration against Muslims in Denmark and in the world."
Some were also concerned by the escalation of the cartoon affair and the offence Muslims feel the drawings have caused.
Helle Mortensen, a 17-year-old protestor, said: "This affair has gone much too far and it's clearly the fault of the Danish government.
"Freedom of expression does not mean hurting others"
"Freedom of expression does not mean hurting others."
The 12 cartoons of the prophet, first published in September 2005 by the conservative Danish newspaper Jyllands-Posten, have caused uproar in the Muslim world and sparked a new cultural battle over freedom of speech and religious tolerance.
Muslims have demonstrated against Danes and other Europeans, burnt Danish flags and boycotted the country's products.
Danish ambassadors have been recalled and Westerners in Muslim countries threatened.
The Danish Front, in a statement ahead of its own demonstration, said it was protesting against "the lenience by the Danish elite in the face of recent attacks by Muslims against our country and our flag".
The extreme-right organisers called for demonstrators to march calmly, but said that "one can almost expect that the anti-racists are fantasising about a violent confrontation".
"We are here to ... express our criticism of a lenient government towards Muslim aggression against our freedom of expression"
Danish Front spokesman
Julius Boergesoen, the spokesman for the Danish Front, said: "We are here to protect our freedom of expression and express our criticism of a lenient government towards Muslim aggression against our freedom of expression."
Many stores had removed their shop window display after police had warned that the left-wing demonstration could include "troublemakers"; but there was no violence beyond an occasional call of "Nazi pig" addressed to the far-right marchers, who were clearly outnumbered by their rivals.
About 100 Danish Muslims joined the left-wing demonstration "because we want to show the world that Muslims are not terrorists", Bassen, a 20-year-old demonstrator, said.