In 2009, a shooting rampage at the same Army base left 13 people dead.

Lt Gen Milley said there was no indication of terrorism in the latest attack, but added: "We're not ruling anything out."

The gunman, identified as Army Specialist Ivan Lopez, served in Iraq for four months in 2011.

Lieutenant General Mark Milley addresses the media at Fort Hood

He had sought help for depression, anxiety and other problems, and had been undergoing an assessment to determine whether he had post-traumatic stress disorder, Lt Gen Milley said.

The commanding officer described how the shooter "walked into one of the unit buildings, opened fire, got into a vehicle, fired from the vehicle, got out of the vehicle and opened fire again in another building".

"A military police officer responded. He was approaching her at about 20 feet. He put his hands up, then reached under his jacket.

"He pulled out his gun, she pulled out her weapon, she then engaged and he put the weapon to his head" killing himself.

Lt Gen Milley said the motive was unclear. He said initial reports suggested "there may have been an argument in one of the unit areas".

All those hit by the soldier's recently purchased 45-calibre semi-automatic weapon were in the military. The gun had not been registered at the base.

Lopez arrived at Fort Hood in February. He was married and had a family.

President Barack Obama said he was "heartbroken" that the base had suffered again after the 2009 rampage.

Video:Shooting Victims 'Quite Critical'

"I want to assure everyone we are going to get to the bottom of what happened," said Mr Obama.

"Any shooting is troubling. Obviously this reopens the pain of what happened at Fort Hood five years ago. We know these families; we know their incredible service to this country and the sacrifices they make.

"Our thoughts and prayers are with the entire community and we're going to do everything we can to make sure the community at Fort Hood has what it needs to deal with the current situation and any potential aftermath.

"We're heartbroken that something like this might have happened again."

The condition of those wounded in the attack ranges from "stable to quite critical".

All-clear sirens have now sounded at Fort Hood after several hours of lockdown. Personnel had been told to take shelter and stay away from doors and windows.

Video:'Terrible tragedy' At Fort Hood

Sky's Amanda Walker said: "It's a huge military base. Around 45,000 soldiers are based there and 9,000 civilians.

"We don't know how the gunman got into the base.

"It is absolutely astonishing this has happened again at a secure military base that has had a terrible history with the previous shooting."

Defence Secretary Chuck Hagel called the shooting a "terrible tragedy".

Asked whether security improvements made since the 2009 tragedy have been adequate, Mr Hagel said: "Obviously when we have these kinds of tragedies on our bases, something's not working."

Army psychiatrist Major Nidal Hasan faces the death penalty for the 2009 killing spree, which also injured 30 people.

In statements to the judge, Hasan, an American-born Muslim, suggested he believed the attack was justified as a jihad against the US military campaigns in Afghanistan and Iraq.

The base is the biggest in the US, covering 340 square miles (880 sq km).