FORT HOOD, Texas- President Barack Obama vowed on Tuesday to make sure the gunman who killed 13 people in a rampage at a U.S. Army base in Texas pays for his crimes.

Leading a memorial service for victims of an attack blamed on a Muslim Army psychiatrist, Obama reminded Americans they were enduring trying times while fighting wars in Iraq and Afghanistan but said there was no justification for what he called an incomprehensible tragedy.

No faith justifies these murderous and craven acts. No just and loving God looks upon them with favor, Obama told a crowd of 15,000, many of them soldiers in camouflage, on a parade ground outside Fort Hood's headquarters.

And for what he has done, we know that the killer will be met with justice -- in this world, and the next.

The shootings marked the latest blow to a U.S. military under strain from its combat duties as Obama weighs sending thousands more troops to the increasingly unpopular war in Afghanistan even as he winds down America's role in Iraq.

The somber ceremony came amid questions about whether authorities missed warning signs about the alleged gunman, Major Nidal Malik Hasan, who spent years counseling severely wounded soldiers and was soon to be deployed to Afghanistan.

Relatives have said Hasan, who is of Palestinian descent, wanted to leave the Army to avoid being sent to Afghanistan and was harassed by fellow soldiers because of his religion. The wars in Iraq and Afghanistan have stoked anti-U.S. sentiment among many Muslims worldwide.

Intelligence agencies learned Hasan had contacts with an Islamist sympathetic to al Qaeda and relayed that information to authorities before he allegedly went on the shooting spree, officials said on Monday.

No action was taken against Hasan by federal authorities, who determined the information gave no hint he was planning an attack or was taking orders from Anwar al-Awlaki, a fiery, anti-American cleric based in Yemen.

OBAMA PAYS TRIBUTE

Five days after the attack, the president and first lady Michelle Obama flew to Texas, where he honored the victims in public and met privately with their families and some of the 30 people wounded in the shootings.

We are a nation of laws whose commitment to justice is so enduring that we would treat a gunman and give him due process, just as surely as we will see that he pays for his crimes, Obama said.

Obama invoked the September 11 attacks of 2001 as he tried to rally the spirits of the troops.

These are trying times for our country. In Afghanistan and Pakistan, the same extremists who killed nearly 3,000 Americans continue to endanger America, our allies and innocent Afghans and Pakistanis, he said.

As we face these challenges, the stories of those at Fort Hood reaffirm the core values that we are fighting for.

Investigators tried to interview Hasan on Sunday at the military hospital where he was recovering from gunshots that subdued him during the attack but he invoked his right to speak to a lawyer, government officials said.

They declined to speculate about his possible motive.

The shootings took place at Fort Hood's crowded Soldiers Readiness Processing Center, where troops get medical checkups before deploying abroad. Authorities have decided to charge Hasan in a military court, officials said.

(Writing by Matt Spetalnick; Editing by John O'Callaghan)