Image copyright Getty Images Image caption Kelley is believed to have been in a family row with his ex-wife and in-laws, police say

Texas church gunman Devin Patrick Kelley was armed with three guns and had argued with his mother-in-law before the rampage, officials say.

The attack on the small church outside San Antonio during Sunday services left 26 people dead - half were children.

Kelley called his father after he was shot by an armed bystander and said he did not think he would survive.

US officials said he was not legally permitted to own the weapons, including a semi-automatic rifle and two pistols.

Freeman Martin, the regional director for the Texas Department of Public Safety, told reporters it appeared that Kelley died from a self-inflicted gunshot wound after first being shot by a "good Samaritan".

Media playback is unsupported on your device Media caption 'Our kids play together,' says a resident whose neighbours are feared dead

"This was not racially motivated, it wasn't over religious beliefs," Mr Martin said.

"There was a domestic situation going on with the family and in-laws," he said, adding that Kelley had sent threatening texts to his mother-in-law.

"We know that he expressed anger towards his mother-in-law, who attends this church," Mr Martin added.

His mother-in-law, Michelle Schields, was not present during the shooting at the First Baptist Church of Sutherland Springs.

However, her mother, Lula White, was killed in the hail of bullets, according to relatives' Facebook posts and interviews with the New York Daily News.

Media playback is unsupported on your device Media caption How the Texas church mass shooting unfolded

Kelley fled the scene after exchanging gunfire with a local resident who heard gunshots coming from across the road, Mr Martin said on Monday.

Johnnie Langendorff told local media that he picked up the Texas man, identified by US media as Stephen Willeford, and the pair pursued Kelley in a car chase.

He said they drove at speeds of up to 95mph (153km/h) until the gunman lost control of his car and crashed.

Kelley was later found dead inside his vehicle with what appeared to be a self-inflicted gunshot wound, police said.

Who were the victims?

Wilson County Sheriff Joe Tackitt said between 12 and 14 children were among those killed in the attack in Sutherland Springs, a small town 30 miles (50km) south-east of the city of San Antonio.

The youngest of those who died was only a year old.

As many as eight members of the Holcombe family were killed in the shooting, the Washington Post reported.

The BBC spoke to the Holcombes' neighbour Pauline Garza, who said the family did not come back from church.

The First Baptist Church's pastor, Frank Pomeroy, told US media his 14-year-old daughter, Annabelle, was among those killed.

Media playback is unsupported on your device Media caption 'Belle died with her church family,' her mother said

Officials said 23 people were found dead inside the church while two people were fatally shot outside. Another died in hospital, authorities said.

Of the 20 wounded, 10 are in hospital in a critical condition.

Who was the gunman?

Kelley was court-martialled in 2012 after he was accused of assault against his wife and step-son. He was sentenced to 12 months' confinement.

He received a "bad conduct" discharge two years later, according to Ann Stefanek, a US Air Force spokeswoman.

Texas Governor Greg Abbott said: "It's clear this is a person who had violent tendencies, who had some challenges, and someone who was a powder keg, seeming waiting to go off."

Mr Abbott added that the attacker should not legally have been allowed to own a firearm, after having been denied a gun owner's permit by the state.

Kelley worked till last July as a security guard for an amusement park run by the Schlitterbahn company in New Braunfels near Sutherland Springs.

His employment was "terminated" after just over five weeks, the company said.

He had a licence to work as an unarmed security guard, a job that police described as "similar to a security guard at a concert-type situation".

"There were no disqualifiers entered into the national crime information database to preclude him from receiving a private security licence," police said.

How did Kelley obtain a gun?

Analysis by Anthony Zurcher, BBC News, Washington

He was kicked out of the US Air Force, but how it happened may be important in understanding how he was able to purchase the weapons he used to kill 26 individuals in Sutherland, Texas.

Individuals who have been dishonourably discharged from the US military are prohibited from possessing firearms. Kelley had a "bad conduct" discharge, which is a level below "dishonourable" and didn't automatically qualify for a ban.

Kelley received his discharge because he was convicted in a military court of assaulting his wife and child, which - under federal and Texas law - could have been deemed a domestic violence incident that would have prevented him from purchasing a firearm.

In addition, if the conviction was classified as a felony, that too would have been an automatic disqualification.

The key, it seems, is translating a court martial verdict into its civilian equivalent. A prison sentence of a year or more, which Kelley received from the military court, is also grounds for a gun-ownership prohibition.

None of this apparently came up on Kelley's instant background check when he sought to buy firearms from a sporting goods store in Texas, however. Kelley also did not disclose details of his military criminal justice record on his purchase paperwork.

Media playback is unsupported on your device Media caption After the Las Vegas attack in October 2017 the BBC looked at how US mass shootings are getting worse

The shooting comes just a month after a gunman in Las Vegas opened fire on an outdoor music festival, killing 58 people and wounding hundreds in the deadliest mass shooting in recent US history.