A gunman has tried to shoot a Danish writer and prominent critic of Islam, but the writer managed to fend off his assailant and was not injured in the attack.

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. 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 (£570) in 2011 for making a series of insulting and degrading statements about Muslims, but appealed against the conviction and was acquitted by the Danish supreme court in April 2012.

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 using his freedom of expression," she told the Danish news agency Ritzau.

Hedegaard has expressed support for a range of outspoken critics of Islam in Europe, including the 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".

• This article was amended on 7 February 2013, because it said that Lars Hedegaard was fined but did not point out that his conviction was later quashed by a higher court.