The gunman accused of the worst mass murder in Texas history may have been hunting for his mother-in-law when he arrived at a small-town Baptist church and unleashed hell with a Ruger assault-type rifle, investigators said Monday.

But Devin Patrick Kelley’s potential target was not at the First Baptist Church in Sutherland Springs when he opened fire on Sunday, killing 26 people ranging in age from 18-months old to 77 — with almost half of the victims children.

Now the targeted woman is talking to investigators who are trying to come up with a motive for the deadliest massacre ever at an American house of worship— and police are trying to determine how a man who got a bad conduct discharge from the Air Force for assaulting his wife and cracking her infant son's skull was able to buy four guns.

“We can tell you there was a domestic situation going on in this family," Commander Freeman Martin of the Texas Department of Public Safety said at a briefing. “The suspect’s mother-in-law attended this church.”

"She has received threatening text from him,” said Martin, who did not identify the woman or elaborate on the content of the messages.

“We know he expressed anger towards his mother-in-law, who attended this church,” he said.

Freeman’s remarks echoed what Texas Gov. Greg Abbott told "TODAY" earlier.

“The information may be coming out today or tomorrow, in the coming days, but I don’t think this was a random act of shooting, “ Abbott said.

Kelley's mother-in-law from his most recent marriage in 2014 lives in Sutherland Springs, records show. His first marriage ended in divorce in 2012 in New Mexico.

Twenty-three people were killed inside the sanctuary, Martin said, adding that they have "a video recording from inside the church." Two more were killed outside the building and one died later at a hospital.

Martin warned that the death toll "could rise" because half of the 20 wounded victims are in critical condition.

Kelley was found dead after the massacre in his vehicle — apparently from a self-inflicted gunshot wound, Martin said. A Glock and a Ruger handgun were found inside the Ford Expedition he had been driving and a Ruger AR-556 rifle was recovered at the church, he said.

Kelley, who was 26 and lived in nearby New Braunfels, had been wounded earlier when he got into a gunfight outside the church with a man who lived nearby and was armed with at AR-15 assault-type rife, Martin said.

Martin did not identify the “hero Texan” who traded shots with Kelley. But he said that as Kelley raced away from the crime scene “the suspect did notify his father that he had been shot and that he was not going to make it.”

Meanwhile, investigators were trying to figure out how Kelley was able to build his mini-arsenal, which consisted of two weapons purchased in Colorado and two more bought in Texas.

“In general, if an individual has a dishonorable discharge from the military, they would be precluded from buying a firearm,” said Fred Milanowski, the agent in charge for the Bureau of Alcohol, Tobacco, Firearms and Explosives.

A former member of the Air Force, Kelley was court-martialed in 2012 on two charges of assaulting his spouse and their child. He was confined for a year and then discharged for bad conduct in 2014.

Don Christensen, a retired Air Force colonel who supervised prosecutors when Kelley was brought before a court martial, told NBC News he was convicted of fracturing the skull of his infant stepson.

"I don't know how old the child was, but he was a baby," said Christensen.

Kelley was also convicted of assaulting his wife, Tessa, in the same incident in 2012, he added. The incident happened while Kelley was stationed at Holloman Air Force Base in New Mexico.

Under federal law, anybody with a dishonorable discharge is not authorized to buy a gun.

Abbott said Kelley had applied for a Texas right-to-carry permit and had been turned down.

“It was after that that he was able to buy this gun,” Abbott said. “So there’s ongoing information that needs to be gathered.”

Sutherland Springs is a tight-knit town of about 400 people about 40 miles southeast of San Antonio.

Dressed in black tactical gear, Kelley opened fire just after 11 a.m. Sunday outside the church and then barged inside and began spraying the sanctuary with bullets.

Terrie Smith told MSNBC she watched the deadly drama unfold from a store across the street.

"He was shooting towards the church and he ran around the church," Smith said, adding that while this was going on she and the customers took shelter inside the store.

"Then there was silence," she said. "We didn't hear any more shots for a couple of seconds. And then we heard a massive load of shots."

Choking up with tears, Smith said "I believe that was when he was in the church."

"We couldn't do anything because we didn't know if there was more of them," she said. "And all of a sudden we see one of the victims running out and he came across the street toward the store and there was blood on his arms and part of his face and we let him in the store."

The wounded man, Smith said, told them "his family's in there."

Inside the church, Kelley's rampage was cut short when an unidentified good Samaritan wrenched the rifle out of his hands.

Kelley then fled the church where he was confronted by an armed man who lives near the church and a gun battle erupted.

After Kelley fled, another man police are calling a hero named Johnnie Langendorff pulled up in his truck, told the neighbor to hop in and together they began chasing after the fleeing Kelley.

When they caught up to Kelley’s vehicle about 11 miles north of the church, it was in a ditch and the gunman had already shot himself, Martin said.

Two ex-girlfriends told NBC News that Kelley had a short fuse and his behavior was disturbing and even violent after they broke up with him.

“That was another thing about him — he was very sick in the head,” former flame Katy Landry told NBC News in a Facebook message. “He would tell me very sick strange things.”

Kelley had some minor traffic violations on his police record in Comal County, where he lived. But in Colorado Springs, Colorado, where he lived for a short time, he was arrested in 2014 on an animal cruelty charge, according to court records.

Details about that case were not immediately available.