NEW BRAUNFELS, Tex. — He beat his wife, cracked his toddler stepson’s skull and was kicked out of the military. He drove away friends, drew attention from the police and abused his dog. Before Devin P. Kelley entered a rural Texas church with a military-style rifle, killing at least 26 people on Sunday, he led a deeply troubled life in which few in his path escaped unscathed.

In 2012, while stationed at Holloman Air Force Base in New Mexico, Mr. Kelley was charged with assault, according to Air Force records, which said he had repeatedly struck, kicked and choked his first wife beginning just months into their marriage, and hit his stepson’s head with what the Air Force described as “a force likely to produce death or grievous bodily harm.”

“He assaulted his stepson severely enough that he fractured his skull,” said Don Christensen, a retired colonel who was the chief prosecutor for the Air Force, adding, “He pled to intentionally doing it.”

Prosecutors withdrew several other charges as part of their plea agreement with Mr. Kelley, including allegations that he repeatedly pointed a loaded gun at his wife.

He was ultimately sentenced in November that year to 12 months’ confinement and reduction to the lowest possible rank. His final duty title was “prisoner.”

His first wife, Tessa Kelley, divorced him while he was confined and was awarded the couple’s only four household items of value: a television, an Xbox, a wedding ring and a revolver.

After his confinement, Mr. Kelley was forced out of the military with a bad conduct discharge. The Air Force said the conviction should have barred Mr. Kelley from owning any guns. Instead, law enforcement officials say, he bought several.

Friends from New Braunfels, Tex., where he went to high school, expressed shock in the aftermath of the shooting, remembering how Mr. Kelley was a friendly, if awkward, teenager who grew up active in his church. His senior yearbook photo shows him smiling, with untamed hair and a Hollister T-shirt. But in recent years, friends said, he grew so dark that many unfriended him on Facebook.

“I had always known there was something off about him. But he wasn’t always a ‘psychopath,’” a longtime friend, Courtney Kleiber, posted on Facebook on Sunday. “We had a lot of good times together. Over the years we all saw him change into something that he wasn’t. To be completely honest, I’m really not surprised this happened, and I don’t think anyone who knew him is very surprised either.”

Instead of straightening out after his bad conduct discharge, Mr. Kelley began a long downward slide that culminated in the shooting Sunday.

After getting out of confinement, Mr. Kelley moved into a barn at his parents’ house, which they had converted into an apartment, according to the local sheriff’s office records.

During the next two years, he was investigated twice for abusing women. The authorities in Comal County, which includes Mr. Kelley’s hometown New Braunfels, released records on Monday that showed he had been the subject of an investigation for sexual assault and rape in 2013.

The investigation ended without the filing of any charges — Mr. Kelley’s only skirmishes in the local courts were traffic violations.

Image Devin P. Kelley Credit... via Texas Department of Public Safety

Less than a year after the sexual assault report, deputies were summoned again after Mr. Kelley’s girlfriend at the time, Danielle Shields, reportedly sent a text message to a friend saying she was being abused. Deputies who responded told a dispatcher, according to the report, that it was a “misunderstanding and teenage drama.” Mr. Kelley married Ms. Shields two months later, local records show.

At the time of both episodes, Mr. Kelley’s appeals were still pending before military courts.

Mr. Kelley was finally discharged from the Air Force in 2014. He married Ms. Shields in April that year. Law enforcement officials described their relationship this week as “estranged.”

A few months after the wedding, the couple moved to Colorado Springs, where voter registration documents list his address as Parking Space 60 at a collection of trailers in a gravel lot called the Fountain Creek RV Park.

A woman living in a camper next door, who gave her name only as Susan, said a man of similar age and description lived in Spot 60 for a few months during that time.

“He was kind of off,” she said as she loaded blankets into one of the RV park’s washing machines.

He said hello a few times in passing but was never friendly and stayed only a few months, she said. She never heard any arguments from his trailer.

“The only thing that sticks out about him was his dog,” she said.

He had a puppy that he kept tied up in the sun all day outside his RV without water, she said. She also recalled an episode in which the police were called because he had struck the dog repeatedly in the head.

Records show Mr. Kelley was charged with cruelty to animals, a misdemeanor, in August 2014, pleaded guilty and was given a deferred sentence. He moved out a few weeks later, she said.