Three American soldiers have been killed and 16 others injured at Fort Hood army base in Texas by another soldier who later shot and killed himself.
Base commander Lieutenant General Mark Milley said the gunman, who served in Iraq in 2011, was being treated for depression and anxiety, and being checked for possible Post-Traumatic Stress Disorder.
General Milley said the man used a .45-calibre semi-automatic pistol, which he bought recently and apparently smuggled onto the base. He opened fire in a medical building on Wednesday, got into a vehicle while still shooting and then went to another building.
When challenged by a member of the military police in a carpark, the man turned the gun on himself. The general praised the servicewoman's courage, saying it was "clearly heroic."
The gunman, who was married and on medication, and had reportedly told officials that he had suffered a traumatic brain injury.
The US army base remained on lockdown for a couple of hours after staff were ordered to shelter in place, but personnel and family members were later given the all-clear, AFP reports.
The incident sparked memories of the November 2009 shooting at Fort Hood, when army psychiatrist Major Nidal Hasan killed 13 people and wounded 32 others after going on an al Qaeda-inspired shooting spree.
Hasan, who was shot during the attack and is partially paralysed, was sentenced in September last year to death. The US-born Muslim of Palestinian descent is awaiting execution.
President Barack Obama said on Wednesday he was "heartbroken something like this might have happened again," and pledged that investigators would "get to the bottom of what happened."
"Obviously, this reopened the pain of what happened at Fort Hood five years ago. Many of the people there have been on multiple tours in Iraq and Afghanistan. They serve with valour, they serve with distinction. At when they're at their home base, they need to feel safe."
Fort Hood is spread out over almost 900 square kilometres, and is the largest US military base with a population of 70,000 including 42,000 military personnel. The rest are family and civilian staff.