Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

A "heroic" female cop ended Wednesday’s Fort Hood shooting rampage by confronting an Iraq war vet who had killed three colleagues and wounded 16 others.

The military police officer was only 20 feet from the gunman – who was named by officials as Ivan A. Lopez, a 34-year-old who was being treated for depression and anxiety.

Lopez, who had also "self-reported" a traumatic head injury during service, later took his own life.

Three of the wounded were still fighting for their lives in the intensive care unit of a nearby civilian hospital, doctors said early Thursday.

The Morning Rundown Get a head start on the morning's top stories. This site is protected by recaptcha

The shooting spree came 4½ years after 13 people died in a rampage on the same Texas base.

Lopez was carrying his semi-automatic weapon in a parking lot when confronted by the female officer, Fort Hood’s commanding officer told reporters.

"He was approaching her at about 20 feet. He put his hands up, then reached under his jacket, pulled out the (.45) and she pulled out her weapon and then she engaged, and he then he put the weapon to his head," Lt. Gen. Mark Milley said late Wednesday.

The female police officer's actions appeared to prompt the end of the killing spree.

“What she did was heroic,” Milley added. "She did her job and she did exactly what we’d expect from U.S. Army military police.”

Earlier, Lopez had opened fire in one building on the base before getting into a vehicle and firing more shots there and in another building.

Lopez was using a .45-caliber Smith & Wesson semiautomatic pistol. Private firearms aren't allowed at Fort Hood, and the weapon — which Milley said was bought locally recently — wasn't registered with base authorities.

Milley said an investigation involving “all appropriate federal agencies” has already begun into what triggered the rampage, which officials believe began with an argument in the motor pool of the base and escalated.

Lopez, a married father, served four months in Iraq in 2011. Milley said he wasn't wounded in action but had "self-reported" a traumatic head injury.

Investigators are “digging deep” into Lopez’ background including “any criminal history…experiences… all the things you would expect us to be doing are being done right now,” he said.

- Alastair Jamieson