Updated at 8:30 p.m. ET

The Air Force says a mistake allowed Devin Patrick Kelley to buy guns. On Sunday Kelley opened fire on a small church in Sutherland Springs, Texas.

The former airman had an assault-style rifle and two handguns — all purchased by him, according to federal officials — when he shot and killed 26 people.

He also had a known record of domestic violence. In 2012, while he was in the U.S. Air Force, he was court-martialed for assaulting his then-wife and stepson. He served a year in confinement at a Naval facility in California after a plea bargain.

Under federal law, his conviction disqualified him from legally possessing a firearm. But there was an apparent breakdown in getting information about his conviction to the proper federal database.

"Initial information indicates that Kelley's domestic violence offense was not entered into the National Criminal Information Center database by the Holloman Air Force Base Office of Special Investigations," said Air Force spokesperson Ann Stefanek in an email.

Top Air Force brass have ordered a complete review of the case.

Kelley purchased four guns over a four-year period beginning in 2014, according to federal officials; all those purchases were made after his court-martial conviction and discharge.

An official at the Pentagon tells NPR's Tom Bowman that a mistake resulted in neither the arrest nor the conviction being listed in the National Instant Criminal Background Check System, the database that would have flagged him as ineligible to purchase a firearm.

"This was mishandled by the Air Force Office of Special Investigations at Holloman Air Force Base in New Mexico, where Kelley was serving when he was arrested," Tom reports. "An investigation is now underway, and the Air Force is taking it very seriously, said the source."

"The Service will also conduct a comprehensive review of Air Force databases to ensure records in other cases have been reported correctly. The Air Force has also requested that the Department of Defense Inspector General review records and procedures across the Department of Defense," said Stefanek.

Retired Col. Don Christensen, who was the chief prosecutor for the Air Force at the time of Kelley's general court-martial, tells NPR that the case was serious.

"He fractured his baby stepson's skull," Christensen says.

Kelley accepted a deal, pleading guilty to a charge of assault on his wife and to a charge of "intentionally inflicting grievous bodily harm" on the child, Christensen says. His crimes were punishable by up to five years confinement (the military equivalent of a prison term). As part of the deal, Kelley received an 18-month cap on his confinement and was ultimately sentenced to 12 months.

Kelley's punitive discharge — a bad conduct discharge — did not prohibit him from owning a gun, as a dishonorable discharge would have.

But under federal law, anyone convicted of "a crime punishable by imprisonment for a term exceeding one year" is prohibited from possessing a firearm. The same is true for anyone convicted of "a misdemeanor crime of domestic violence" under a provision that allows no exception for the military or law enforcement.

Kelley's conviction qualified under both categories, Christensen says.

NPR's Martin Kaste reports that Academy Sports & Outdoors, a store that sold Kelley guns, says it ran a background check on Kelley twice in the past two years. Kelley passed each time, the company says.

If Kelley's convictions were never uploaded into the system, that could easily explain how he passed. But even if they had been uploaded, there might still have been trouble getting information into the right hands — there's a sort of language barrier between military and civilian justice systems, Christensen says, with different terms for the same kinds of crimes. If the military described a general court-martial for assault, with a sentence of one year, the civilian authorities might "never realize" it was a domestic violence conviction punishable by five years, he says.

In general, there are some " gaping holes" in the current background check system, as NPR's Danielle Kurtzleben reported last year, which can allow people who should fail background checks to buy guns anyway. And if Kelley had purchased a gun from a private seller, he wouldn't have had to pass a background check at all, Martin notes.

Meanwhile, Texas Gov. Greg Abbott says Kelley applied for a license to carry a gun and was rejected, Martin reports. He notes that Texas requires a background check but also has additional training and tests that Kelley may not have completed.

Copyright 2017 NPR. To see more, visit http://www.npr.org/.