COPENHAGEN (AP).- A Somali man was charged Saturday with two counts of attempted murder for an attack on a Danish artist whose 2005 cartoon of the Prophet Muhammad ignited riots and outrage across the Muslim world, authorities said.

The 28-year-old Somali  who had ties to al-Qaida  broke into Kurt Westergaard's home in Aarhus on Friday night armed with an ax and a knife, said Jakob Scharf, head of Denmark's PET intelligence agency.

The 75-year-old artist, who has been the target of several death threats since depicting the Prophet Muhammad with a bomb-shaped turban, pressed an alarm and fled with his 5-year-old granddaughter to a specially made safe room.

Officers arrived two minutes later and tried to arrest the assailant, but then shot him in the hand and knee when he threatened them with the ax, said Preben Nielsen of the Aarhus police.

Nielsen said the man's wounds were serious but not life-threatening, and Westergaard was "quite shocked" by the attack but was not injured.

The Somali man denied the charges at a court hearing Saturday in Aarhus, Denmark's second largest city, 125 miles (200 kilometers) northwest of Copenhagen. Accompanied by a lawyer, he was wheeled into the court on a stretcher from the hospital where he was being treated.

Chief Superintendent Ole Madsen in Aarhus said the man was charged with two counts of attempted murder: one on Westergaard and one on a police officer. The court also banned publication of the man's name.

"He will be in custody for four weeks, and in isolation for two," Madsen said, adding that the Somali would be moved to the Vestre Faengsel prison in Aarhus, which has medical facilities.

His defense lawyer, Niels Christian Strauss, told reporters outside the court he had urged his client to remain silent during the hearing to give him more time to examine the evidence.

Westergaard remains a potential target for extremists nearly five years after he drew a caricature of the Prophet Muhammad along with 11 others that were printed in the Jyllands-Posten newspaper.

The drawings triggered riots and protests in the Muslim world, and Danish and other Western embassies in several Muslim countries were torched a few months later in 2006 by angry protesters who felt the cartoons had profoundly insulted Islam.

Islamic law generally opposes any depiction of the prophet, even favorable, for fear it could lead to idolatry.

The Somali man had won an asylum case and received a residency permit to stay in Denmark, Scharf said, declaring the Friday attack "terror related."

"The arrested man has, according to PET's information, close relations to the Somali terrorist group al-Shabab and al-Qaida leaders in eastern Africa," Scharf said. "(The attack) again confirms the terror threat that is directed at Denmark and against the cartoonist Kurt Westergaard in particular."

Scharf said the man is suspected of having been involved in terror-related activities in east Africa and had been under PET's surveillance but not in connection with Westergaard.

Westergaard could not be reached for comment. However, he told his employer, the Jyllands-Posten newspaper, that the assailant shouted "Revenge!" and "Blood!" as he tried to enter the bathroom where Westergaard and the child had sought shelter.

"My grandchild did fine," Westergaard said, according to the newspaper's Web site. "It was scary. It was close. Really close. But we did it."

Westergaard has received previous death threats and was the subject of an alleged assassination plot.

In October, terror charges were brought against two Chicago men who planned to kill Westergaard and newspaper's former cultural editor.

In 2008, Danish police arrested two Tunisian men suspected of plotting to kill Westergaard. Neither suspect was prosecuted. One was deported and the other was released Monday after an immigration board rejected PET's efforts to expel him from Denmark.

Throughout the crisis, then-Prime Minister Anders Fogh Rasmussen distanced himself from the cartoons but resisted calls to apologize for them, citing freedom of speech and saying his government could not be held responsible for the actions of Denmark's press.

An umbrella organization for moderate Muslims in Denmark condemned the Friday attack.

"The Danish Muslim Union strongly distances itself from the attack and any kind of extremism that leads to such acts," the group said in a statement.