The artist - 74-year-old Kurt Westergaard - was moved to an undisclosed location for his own protection.
The 28-year-old Somali man with ties to al Qaeda broke into 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.
Westergaard, 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. He had been under round-the-clock protection by Danish security agents.
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 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 other Danish cartoonists that were printed in the Jyllands-Posten newspaper. Since Westergaard's cartoon is viewed the most provocative, he is the only of the twelve to live under round-the-clock protection.
The Jyllands-Posten had asked Danish cartoonists to draw Muhammad as a challenge to a perceived self-censorship, not to insult Muslims. Still, 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 Qaeda 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."
Westergaard (left) could not be reached for comment. However, he told his employer, the Jyllands-Posten, 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. That trial has not yet begun.
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.
By Associated Press Writer Jan M. Olsen