"We don't want our government to have any diplomatic relations with these two countries," said Maulawi Abdul Hadi, one of the clerics organizing the protest. "We don't want Danish and Dutch troops in Afghanistan. They should be kicked out of the NATO forces here."
Denmark has 780 troops in Afghanistan as part of NATO's International Security Assistance Force and the Netherlands has 1,650.
Hadi said about 100 clerics and madrassa students launched Sunday's protest.
The crowd swelled to about 700 before dispersing, provincial police spokesman Sher Jan Durrani said, adding that the protest was peaceful.
Hadi said the organizers ended the protest after two and half hours because it had grown too large and they were concerned it might turn violent.
Last month in a gesture of solidarity, Denmark's leading newspapers reproduced cartoons of the Prophet Muhammad after Danish police said they uncovered a plot to kill the artist, whose drawings sparked deadly riots across the Muslim world in 2006.
The reproduction triggered another wave of protests in recent weeks.
The Afghans were also angered by a short film by a Dutch lawmaker that portrays the Quran as a "fascist book."
Afghanistan is a Muslim nation where blasphemy of Muhammad and the Quran is considered a serious crime that carries the death sentence.