The gunman who opened fire in a rural Texas church last year, killing 26 people and murdering as many as three generations of one family, could have been stopped from legally obtaining a firearm if the Air Force hadn't shirked its duty, according to a newly released Defense Department report.

Devin Patrick Kelley. Texas Department of Public Safety / via AP

Following the November 2017 mass shooting in Sutherland Springs, the Air Force confirmed that airman Devin Patrick Kelley was court-martialed in 2012 on two charges of assaulting his wife and stepson. The 26-year-old, who had been based in New Mexico, was confined for a year, saw his rank reduced and given a bad conduct discharge in 2014.

But the Air Force should have also submitted his fingerprints to the FBI, and failed to do so on four occasions, the Defense Department's 131-page inspector general report found.

Kelley's conviction should have also triggered the Air Force to send a final disposition report to the agency, which would have put him in the FBI's criminal history database and potentially prevented him from legally buying a gun.

Instead, he passed federally mandated background checks and purchased four firearms from licensed dealers.

According to the report, Kelley used three of the guns he bought for the massacre at the First Baptist Church of Sutherland Springs. Armed citizens shot at Kelley as he fled in his car; he later died from a self-inflicted gunshot wound to the head.

One reason for the lapse in reporting of Kelley's fingerprints to the FBI occurred when a case agent investigating the domestic assault said they didn't know it was a requirement.

Other agents could not give a "clear, supportable reason or explanation" for why Kelley's fingerprints were not submitted to federal authorities, the report said.

"The investigators and confinement personnel had a duty to know, and should have known" the policies, the report added, and "the failures had drastic consequences and should not have occurred."

In the wake of the shooting, Air Force officials asked the inspector general to look into Kelley's past and combed through its databases for other cases where fingerprints were not given to the FBI.

In its report, the inspector general gives several recommendations for the Air Force, including implementing a background check system during recruiting. It was found that Kelley had multiple instances of alleged criminal activity before entering the Air Force, including one just days before he became active.

Investigators said the attack occurred after a domestic dispute Kelley had with his mother-in-law, a member of the church who wasn't present that day. The victims ranged from a pregnant woman and her unborn child to a 77-year-old grandfather, and the shooting became the deadliest inside a house of worship in modern U.S. history.