Here are key moments from the Senate Armed Services Committee hearing on Thursday where Secretary of the Army John McHugh and Army Chief of Staff Ray Odierno testified about Wednesday's shooting at Fort Hood, Tex. (Sarah Parnass/The Washington Post)

The soldier who went on a shooting rampage at Fort Hood, Tex., had a history of mental illness and had been taking medication for anxiety and depression, but Army leaders said Thursday that they had not considered him a potential threat.

Investigators said they were still trying to clarify a motive for the attack but were focusing on the fragile state of mind of Spec. Ivan Antonio Lopez, a 34-year-old military truck driver and Iraq veteran. Officials said he killed three fellow soldiers and took his own life Wednesday in an outburst of gunfire at one of the country’s largest military installations.

Lopez, a married father of four, was given a full psychiatric evaluation last month and had been prescribed “a number of drugs,” including the sleep aid Ambien, according to Army Secretary John McHugh. But the Army psychiatrist who last saw Lopez found no “sign of likely violence, either to himself or to others,” McHugh told a Senate panel.

Another Army leader described Lopez’s health in more dire terms.

“We have very strong evidence that he had a medical history that indicates unstable psychiatric or psychological conditions,” Lt. Gen. Mark A. Milley, the commanding general of Fort Hood, said at a news conference. “We believe that is the fundamental, underlying causal factor.”

A look at the parallels between shooting massacres at Fort Hood in Texas

Around the same time that Lopez visited the Army psychiatrist, he legally purchased the .45-
caliber Smith & Wesson semi­automatic pistol that he used in the shooting, Army officials said.

The soldier bought the firearm on March 1 from Guns Galore, a store in nearby Killeen, Tex., officials said. The shop is the same one that sold a semiautomatic pistol to Maj. Nidal M. Hasan, the Army psychiatrist and al-Qaeda sympathizer who carried out a mass shooting at Fort Hood in 2009, killing 13 people.

Under Army regulations, soldiers can keep personal firearms but are prohibited from bringing them onto military bases unless the weapons are registered. Army officials said Lopez had not registered his new pistol at Fort Hood.

Practically speaking, they acknowledged, there was little they could have done to prevent him from sneaking a weapon onto the sprawling Army post, where more than 50,000 people work each day. Although military police carry out random security checks, requiring everyone to pass through metal detectors would be “frankly untenable,” said Army Col. Steven H. Warren, a Pentagon spokesman.

Fort Hood officials said Lopez opened fire about 4 p.m. local time. In the space of a few minutes, he shot soldiers in two buildings and kept shooting while in a moving vehicle. In addition to killing three soldiers, he wounded 16 others, three of them critically.

He was finally confronted by a military police officer. Lopez put his arms up at first but then reached for his pistol. The police officer drew her gun as Lopez put the pistol to his head, killing himself, Army officials said.

Milley, the Fort Hood commander, said there was no indication that Lopez had come onto the base to hunt down specific targets. But he said investigators think the truck driver had gotten into a verbal altercation that may have prompted him to start shooting.

“We’re looking into that, trying to determine what the trigger event was,” Milley said, adding that investigators were also examining whether Lopez had financial or marital problems.

Milley said he had no details about reports that Lopez was upset about having had little time to attend his mother’s funeral last year. Milley also said it was “too early to tell” whether Lopez had received sufficient psychiatric help.

Gen. Ray Odierno, the Army chief of staff, described Lopez as “a very experienced soldier” who had served for nine years in the Puerto Rico National Guard before enlisting in the active-duty Army in 2010.

While with the National Guard, Lopez served a one-year deployment in Egypt’s Sinai Peninsula. In 2011, after joining the Army full time, he served four months in Iraq and was one of the last U.S. troops to come home at the end of the war.

McHugh, the Army secretary, told lawmakers that Lopez had “a clean record” in terms of conduct. He said Lopez’s personnel file had “no outstanding bad marks for any kinds of major misbehaviors that we’re yet aware of.”

The Army released a summary of Lopez’s service history, including awards and decorations, but did not provide detailed records or specific information about disciplinary proceedings.

Army leaders said there was no record that Lopez had been wounded or injured in Iraq. But they said he had “self-reported” a possible traumatic brain injury from his wartime service. He had recently been undergoing an evaluation to determine whether he suffered from post-traumatic stress disorder, Army officials said.

Lopez had been stationed at Fort Hood since February and was assigned to the 13th Sustainment Command (Expeditionary) as a truck driver. He had previously been stationed at another Texas base, Fort Bliss, for two years as an infantryman.

According to a person familiar with Lopez’s military service, he had been taking medications while stationed at Fort Bliss to help with depression and anxiety, but his behavior did not raise any red flags. Because of privacy restrictions, his commanders were unaware of the medications he was receiving.

Lopez’s mother had passed away last year, and he had been seeing a chaplain for counseling on that and other undisclosed issues, said the person familiar with the soldier’s military record. The military monitors people for stress levels, and Lopez was deemed “low risk” at the time.

Defense Secretary Chuck Hagel said Thursday afternoon that the Pentagon will be looking for “any new lessons learned” from Wednesday’s shooting.

“We need to let investigators do their work and help us understand how this happened,” Hagel told reporters at a news conference that wrapped up a three-day summit of defense leaders from Asian nations in Honolulu.

In the wake of a mass shooting by a defense contractor at the Washington Navy Yard in September, Hagel ordered a series of security changes at military installations, including more rigorous screening of personnel, and the creation of an analysis center to examine “insider threats.”

The Pentagon also pledged to adopt a raft of other security measures after the 2009 Fort Hood shootings.

Hagel did not respond substantively when asked why the Defense Department had not fully implemented those recommendations.

“Let me assure our country, the people who serve: We do take this seriously,” Hagel said. “We recognize the imperfections,” he added. “Obviously something went wrong.”

Shelby Sementelli in Killeen; Ernesto Londoño in Honolulu; and Sari Horwitz, David Fahrenthold, Tom Hamburger, William Branigin, Colby Itkowitz, Ed O’Keefe and Julie Tate in Washington contributed to this report.