NEW BRAUNFELS, Texas -- Wherever Devin Patrick Kelley went after graduating from high school, a trail of violence followed.

In New Mexico, Kelley was kicked out of the Air Force following a court-martial two years after he enlisted for abusing his wife and reportedly hitting her child hard enough to fracture his skull. In Colorado, he was charged with misdemeanour animal cruelty after someone saw him punch a dog several times. And in Texas, sheriff's deputies were called to his parents' house after his girlfriend told a friend he was abusing her.

Authorities say Kelley opened fire Sunday at the First Baptist Church of Sutherland Springs, Texas, killing 26 people and wounding 20 others.

According to their investigation, Kelley entered the small church during worship services dressed in black tactical gear and carrying an assault rifle. He fired it as he walked down the centre aisle, shooting people who had no way to escape.

Authorities have said the suspect's mother-in-law attended the church and she'd gotten threatening texts from him. Kelley's parents and other relatives did not return numerous messages from The Associated Press seeking comment. But according to military officials and authorities in three states, the 26-year-old Kelley had a history of threatening loved ones with violence.

A native of the San Antonio suburb of New Braunfels, Kelley graduated from high school in 2009, according to a district spokeswoman. He enlisted in the Air Force the following year and was assigned to Holloman Air Force Base in New Mexico, with the responsibility of moving passengers, cargo and personal property in military transportation. He got married for the first time in 2011.

But according to Air Force spokeswoman Ann Stefanek, Kelley faced a court-martial in 2012 on allegations that he abused his wife and a child. According to court-martial documents the Air Force released Monday, Kelley was accused of choking his wife, pulling her hair and kicking her. He also hit the child on the head and body, according to the documents. The Air Force's former chief prosecutor, Don Christensen, told The New York Times that Kelley fractured the child's skull.

Kelley was sentenced to 12 months of confinement and ultimately removed from the military with a bad-conduct discharge and a reduction of rank.

The Air Force acknowledged Monday that it didn't enter Kelley's criminal history into the federal database used to conduct background checks on citizens looking to purchase a firearm. Authorities recovered a Ruger AR-556 rifle at the church and two handguns from Kelley's vehicle. They say all three were purchased by Kelley.

His wife, Tessa Kelley, filed for divorce in 2012, the same year as the court-martial. In paperwork associated with the divorce, Tessa Kelley said she was working at Taco Bell for $7.50 an hour while Devin Kelley was in detention.

The divorce was finalized in October 2012.

Kelley's discharge was complete in 2014, Stefanek said. That February, sheriff's deputies arrived at his family's home in New Braunfels just after 10 p.m. one night to investigate a potential domestic violence case.

Citing a sheriff's office report, Comal County spokesman Paul Anthony said a friend of Kelley's girlfriend told authorities she received a text message from the girlfriend that indicated "her boyfriend was abusing her." The report identifies the girlfriend as Danielle Shields and says Shields reported that "her arms were red." It includes no additional details about what caused them to be red.

Shields said Kelley had "told her to pack a bag," according to the report.

When sheriff's deputies arrived, people at the home said there was a "misunderstanding," according to the report. It doesn't make clear who spoke to deputies. No arrests were made.

Kelley married Shields two months later.

Kelley registered to vote in Colorado in 2014, with an address traced to a mobile home park in Colorado Springs, home to the U.S. Air Force Academy and other Air Force installations. But in August of that year, he was charged with misdemeanour animal cruelty. One neighbour told a deputy that Kelley chased a dog, jumped on top of it and struck the dog with a closed fist several times, according to an incident report released Monday. Another neighbour says Kelley grabbed the young husky, threw it into the air, then onto the ground and dragged it to his camper.

According to local court records, he was given a deferred probationary sentence and ordered to pay $368 in restitution. A protection order was issued against him in January 2015, The Denver Post reported.

He apparently moved back to Texas and sought work as a security guard, obtaining a state private security license in June and getting a job at the Schlitterbahn water park in New Braunfels. But he was fired after less than six weeks, the water park said in a statement.

He then was hired as a security guard at the Summit Vacation Resort, also in New Braunfels. A manager there, Claudia Varjabedian, told the AP that Kelley "seemed like a nice guy" and didn't cause her any problems.

A motive for the mass shooting remains unclear, but Kelley appears to have targeted a church that was long attended by his wife's family.

Leading up to the shooting, authorities say, Kelley had sent threatening text messages to his mother-in-law, who attended the First Baptist Church of Sutherland Springs, about 30 miles (48 kilometres) southeast of San Antonio. Texas Department of Public Safety Regional Director Freeman Martin said there was a domestic situation going on within the family.

According to online records, Danielle Kelley's mother has an address in Sutherland Springs and a Facebook account linked to her lists several members of the church as friends, including the pastor's wife.

A resume posted online linked to an email address associated with Danielle Kelley identifies her as a teacher at the church from 2009 to 2013. Among the responsibilities it listed at the church were to "teach the children about GOD" and "be a positive influence in their life."

The dead inside the church ranged from 18 months to 77 years old. About 20 other people were wounded, 10 of whom were still hospitalized Monday in critical condition.

------

Bajak and Merchant reported from Houston. Associated Press reporters Jim Anderson in Denver, Douglass K. Daniel in Washington, Reese Dunklin and Jamie Stengle in Dallas, and Morgan Lee in Santa Fe, New Mexico, contributed along with AP researcher Randy Herschaft in New York.