The day after a frantic and chaotic hunt for a gunman ended with the realisation that tragedy had again touched a US military base, the search for an explanation began at Fort Hood in Texas as investigators sought to understand what caused a soldier to embark on a shooting spree that left four dead and 16 injured.

For those living at or near the huge installation, halfway between Austin and Waco, Wednesday night's events brought back traumatic memories of another mass shooting on the site in 2009, when an army major killed 13 people and injured more than 30.

The gunman on Wednesday killed three army personnel before turning the gun on himself, authorities said. Of the 16 that were wounded, nine were taken to hospital, three in a critical condition. Counsellors were at the base on Thursday to offer support.

"Any time the army loses a soldier, we all mourn," said army secretary John McHugh, speaking at a previously scheduled Senate committee hearing on Thursday morning. "When that loss comes at the hands of another soldier, and indeed when that event occurs at the very place that suffered so much pain, so much anguish just four and a half years ago, it only adds to the sorrow and the all-consuming sense of loss the amy is feeling this day."

The gunman has been named as Specialist Ivan Lopez. Born in Puerto Rico, the 34-year-old joined the island's National Guard in 1999, said a spokeswoman for the organisation. He enlisted in the US army in 2008 as an infantry soldier and had two deployments as a truck driver but no direct involvement in combat, McHugh said.

An ambulance makes its way to Fort Hood military base near Killeen after first reports that a shooter was at large. Photograph: Ashley Landis/EPA

The motive for the attack was unclear. One possibility is that an argument between soldiers spiralled out of control, Fort Hood's commander, Lieutenant General Mark Milley, told reporters at a briefing on Wednesday night. McHugh said that "possible extremist involvement is still being looked at very, very carefully". He added that Lopez had a clean disciplinary record: "He had a clean record in terms of his behavioral, no outstanding bad marks for any kinds of major misbehaviours that we are yet aware of."

Lopez was seen by army psychiatrists last month. "He was undergoing a variety of treatment and diagnoses for mental health conditions, running from depression to anxiety to some sleep disturbance," McHugh said. He had been prescribed a number of drugs, including Ambien, a sleeping pill.

McHugh said there was no indication from the psychological evaluations that Lopez was likely to commit violence. "He was fully examined and as of this morning we had no indication on the record of the examination that there was any sign of likely violence, either to himself or to others, no suicidal ideation. So the plan forward was just to continue to monitor and to treat him as deemed appropriate."

Lopez was dressed in army fatigues and used a .45 Smith and Wesson semi-automatic pistol that he had recently purchased locally. He did not have permission to bring it on to the base. The incident began around 4pm local time at a medical administration building, Milley said. Lopez then moved to another building and opened fire again. He was confronted by a military police officer in a parking lot. When she drew her weapon he put his gun to his head and pulled the trigger.

Fort Hood is one of the biggest military installations in the world, covering an area of 340 square miles and, according to the military, hosting about 45,000 soldiers and 9,000 civilian employees.

Lieutenant General Mark Milley, the senior officer on Fort Hood, speaks to the media at an entrance to the base. Photograph: Tamir Kalifa/AP

The base was placed on lockdown for about five hours as authorities combed the site in case there were additional threats. As medical first responders and local and federal law enforcement officials rushed to the scene, personnel were told to seek shelter, lock doors and stay away from windows.

Lopez was an active-duty solider who belonged to a brigade that provides logistical support and supplies to other units. Milley said that the suspect was posted to Fort Hood from another installation as recently as February, and had served in Iraq for four months in 2011. Milley said that Lopez self-diagnosed a traumatic brain injury on his return.

He lived with his wife and daughter in an apartment in the nearby town of Killeen. A neighbour, Xanderia Morris, told CNN that they were a friendly, normal-seeming family. She said that Lopez's wife was watching events unfold on television and was worried about her husband but had no idea he was the gunman until he was named by a local station.

It was the third large-scale shooting incident at a US military base since 2009. In November that year, Nidal Hasan, an army psychiatrist, opened fire on a group of Fort Hood soldiers who were about to deploy to Afghanistan. Hasan said at his trial last year that he wanted to defend the Taliban. Last September a military contractor, Aaron Alexis, shot dead 12 people at the Washington navy yard. That prompted defence secretary Chuck Hagel to order a Pentagon review of security at all US military installations worldwide.

US secretary of the army John McHugh, and army chief of staff General Raymond Odierno, arrive for a session of the Senate armed services committee in Washington. Photograph: Gary Cameron/Reuters

Fort Hood's weapons rules were tightened after the 2009 massacre. Only military police and other security personnel are allowed to carry weapons and soldiers with personal firearms must register them with commanding officers and keep them in a locked depository. After the navy yard shooting, Steve Stockman, a Republican congressman from Texas, proposed a bill relaxing the rules on the basis that armed soldiers would be better able to defend themselves if attacked.

Ray Odierno, the chief of staff of the army, said on Thursday that procedures enacted after the 2009 attack, including alert protocols, had helped. "The training that has gone in to the response forces that responded, I think contributed to making this something that could have been much much worse," he told members of Congress.