FORT HOOD, Texas -- An Iraq War veteran being treated for mental illness opened fire at Fort Hood, killing three people and wounding 16 others before committing suicide, in an attack on the same Texas military base where more than a dozen people were slain in 2009, authorities said.

Within hours of the Wednesday attack, investigators started looking into whether the man's combat experience had caused lingering psychological trauma. Fort Hood's senior officer, Lt. Gen. Mark Milley, said the gunman had sought help for depression, anxiety and other problems.

Among the possibilities investigators planned to explore was whether a fight or argument on the base triggered the attack.

"We have to find all those witnesses, the witnesses to every one of those shootings, and find out what his actions were, and what was said to the victims," said a federal law enforcement official who spoke on condition of anonymity, because he was not authorized to discuss the case by name.

The official said authorities would begin by speaking with the man's wife, and expected to search his home and any computers he owned.

The shooter was identified as Ivan Lopez by Texas Rep. Michael McCaul, chairman of the House Homeland Security Committee. But the congressman offered no other details, and the military declined to identify the gunman until his family members had been notified.

Lopez apparently walked into a building Wednesday afternoon and began firing a .45-calibre semi-automatic pistol. He then got into a vehicle and continued firing before entering another building, but he was eventually confronted by military police in a parking lot, according to Milley, senior officer on the base.

As he came within 20 feet (6 metres) of an officer, the gunman put his hands up but then reached under his jacket and pulled out his gun. The officer drew her own weapon, and the suspect put his gun to his head and pulled the trigger a final time, Milley said.

The gunman, who served in Iraq for four months in 2011, had been undergoing an assessment before the attack to determine if he had post-traumatic stress disorder, Milley said.

He arrived at Fort Hood in February from another base in Texas. He was taking medication, and there were reports that he had complained after returning from Iraq about suffering a traumatic brain injury, Milley said. The commander did not elaborate.

The gunman was never wounded in action, according to military records, and there was no indication the attack was related to terrorism, Milley said. His weapon had been recently purchased in the local area and was not registered to be on the base, Milley said.

Lopez was from the U.S. territory of Puerto Rico and joined the island's National Guard in 1999. He went on a peace and security mission to Egypt's Sinai Peninsula in the mid-2000s, and left the National Guard in 2010 to join the U.S. Army, said Lt. Col. Ruth Diaz, spokeswoman for the Puerto Rico National Guard.

Those injured were taken to the base hospital and other local hospitals. At least three of the nine patients were listed in critical condition.

Wednesday's attack immediately revived memories of the 2009 shooting rampage on Fort Hood, the deadliest attack on a domestic military installation in U.S. history. Thirteen people were killed and more than 30 were wounded.

President Barack Obama vowed a complete investigation. In a hastily arranged statement while in Chicago, Obama reflected on the sacrifices Fort Hood troops have made -- including enduring multiple tours to Iraq and Afghanistan.

"They serve with valour. They serve with distinction, and when they're at their home base, they need to feel safe," Obama said Wednesday. "We don't yet know what happened tonight, but obviously that sense of safety has been broken once again."

Army psychiatrist Nidal Hasan was convicted last year for the November 2009 mass shooting at Fort Hood. According to trial testimony, he walked into a crowded building, shouted "Allahu Akbar!" -- Arabic for "God is great!" -- and opened fire. The rampage ended when Hasan was shot in the back by base police officers.

Hasan, now paralyzed from the waist down, is on death row at the military prison at Fort Leavenworth in Kansas. He has said he acted to protect Islamic insurgents abroad from American aggression.

After that shooting, the military tightened base security nationwide. That included issuing security personnel long-barrelled weapons, adding an insider-attack scenario to their training, and strengthening ties to local law enforcement. The military also joined an FBI intelligence-sharing program aimed at identifying terror threats.

In September, a former Navy man opened fire at the Washington Navy Yard, leaving 13 people dead, including the gunman. After that shooting, Defence Secretary Chuck Hagel ordered the Pentagon to review security at all U.S. defence installations worldwide and examine the granting of security clearances that allow access to them.

Asked Wednesday about security improvements in the wake of the shootings, Hagel said: "Obviously when we have these kinds of tragedies on our bases, something's not working."

Associated Press writers Ramit Plushnick-Masti in Houston; Eric Tucker and Alicia Caldwell in Washington; Lolita C. Baldor in Honolulu; and Nedra Pickler in Chicago contributed to this report.