COPENHAGEN—A gunman tried to shoot a Danish writer and prominent critic of Islam, but the writer managed to fend him off and was not injured in the attack, police and an advocacy group he chairs said.

Police said Lars Hedegaard, who heads two groups that claim press freedom is under threat from Islam, was the target of the shooting. In a brief statement, they said a roughly 25-year-old gunman rang the doorbell at the writer’s Copenhagen home and when he opened the door, the gunman fired a shot aimed at his head, but missed.

“After a scuffle the attacker fled. At this writing we do not know whether the police have apprehended him,” the Danish Free Press Society said.

Hedegaard, 70, heads both the Free Press Society and the International Free Press Society. He was fined 5,000 kroner ($1,000 U.S.) in 2011 for making a series of insulting and degrading statements about Muslims.

Denmark’s Prime Minister Helle Thorning-Schmidt condemned the attack. “It is even worse if the attack is rooted in an attempt to prevent Lars Hedegaard to use his freedom of expression,” she told Danish news agency Ritzau.

Hedegaard has expressed support for a range of outspoken Islam critics in Europe, including Swedish artist Lars Vilks and Dutch lawmaker Geert Wilders.

“Failed attack on my friend and Islam critic Lars Hedegaard in Denmark this morning. My thoughts are with him. Terrible,” Wilders tweeted.

The Free Press Society said it was “shaken and angry” over the attack, but “relieved that the perpetrator did not succeed.”