One of the three soldiers killed in the shooting rampage at Fort Hood died while trying to hold a door shut that would have led the gunman to a room packed with military personnel, his fiance says.

The alleged gunman, Spc. Ivan Lopez, later shot and killed himself.

Sgt. First Class Danny Ferguson, a native of Mulberry, Fla., who had just returned from Afghanistan, died while trying to keep the shooter out of the room, Kristen Haley, also a soldier, told WTSP-TV in Tampa, Fla.

“He held that door shut because it wouldn’t lock,” said Haley, who was nearby when the shooting broke out. “It seems the doors would be bullet proof, but apparently they’re not. If he wasn’t the one standing there holding those doors closed, that shooter would have been able to get through and shoot everyone else.”

Army officials say a “verbal altercation” may have preceded the shooting spree, but there is no indication that Lopez, who allegedly opened fire and killed three people and wounded 16, was targeting specific individuals.

There is “strong evidence,” however, that the 34-year-old alleged gunman “had a medical history that indicated an unstable psychiatric or psychological condition,” Lt. Gen. Mark Milley, head of the Army’s III Corps at Fort Hood, said Thursday.

Lopez shot and killed himself after being confronted by a military police officer.

The victims have not been officially identified, but they were all military personnel.

Milley said the shooter walked into a building on the post on the afternoon of April 2 and opened fire, got into a car, fired more shots and then went to another building shooting before he was engaged by the female MP.

He did not elaborate on a possible motive for the shooting, but said the “verbal altercation” involved another soldier or soldiers.

“There is a strong possibility that that immediately preceded the shooting,” Milley said. Lopez purchased the .45-caliber Smith & Wesson handgun used in the shootings at a local gun store March 1.

Last month, according to Fox News Latino, Lopez — purportedly using the name “Ivan Slipknot” on Faecbook — posted comments in Spanish in which he said the “devil had taken him and that he was “full of hatred.”

The post, dated March 1, referred to anger over a belief that he had been robbed.

While the reasons behind the attack remain a mystery, Army officials said that Lopez was being evaluated for post-traumatic stress disorder, but had seen no combat while deployed in Iraq three years ago.

“His records show no wounds, no involvement — direct involvement — in combat,” said Army Secretary John McHugh, the U.S. Army’s top civilian official. “As Gen. Milley said, no record of Purple Heart or any injury that might lead us to further investigate a battle-related TBI (traumatic brain injury) or such.”

Milley said Lopez had “self-diagnosed” a traumatic brain injury. “He was not wounded in action.”

Lopez, a native of Puerto Rico who has been married twice and has four children, enlisted as an infantryman and later switched his specialty to truck driver.

Though he was on a variety of prescribed drugs, including Ambien, he had not yet been diagnosed for post-traumatic stress disorder. But he was undergoing treatment for depression, anxiety, sleep disturbance and a variety of other issues, McHugh said.

“He was seen just last month by a psychiatrist,” McHugh said. “He was fully examined. And as of this morning, we had no indication on the record of that examination that there was any sign of likely violence, either to himself or to others. No suicidal ideation.”

Pentagon regulations require troops who live off base to register weapons if they intend to bring them onto the installations.

“We try to do everything we can to encourage soldiers to register their personal weapons, even when they live off post,” McHugh said. “We are not legally able to compel them to register weapons when they reside off post.”