Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

HOUSTON — Sheriff's deputies didn't pursue a sexual assault investigation against the gunman in a mass shooting at a Texas church, even though the woman reporting it signed a complaint detailing the alleged attack, according to records released Friday.

The records also contradict the reason previously given for why the case stalled against Devin Patrick Kelley, four years before the November 2017 massacre at a tiny church in Sutherland Springs, Texas.

Had Kelley been prosecuted for sexual assault, a conviction could have stopped a trail of violent allegations that culminated in the shooting.

Authorities acknowledged Friday that the alleged victim was not given a forensic exam in June 2013 after reporting the assault, which she said had occurred three days earlier. And the investigation was listed as inactive because a detective at the Comal County sheriff's office couldn't contact Kelley, thinking he had moved. It remained inactive even after deputies were called to Kelley's home in February 2014 to investigate a separate domestic violence complaint against him.

"This was an error on the part of the sheriff's office," Comal County Sheriff Mark Reynolds told The Associated Press on Friday.

Related: Texas shooting exposes gaps in gun background checks

Kelley shot and killed 25 people on Nov. 5, 2017, at the First Baptist Church of Sutherland Springs. Authorities have put the official death toll at 26, because one of the victims was pregnant. Kelley died from a self-inflicted gunshot wound after being shot and chased by two residents when he was leaving the church, authorities have said.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

By that time, Kelley had been court-martialed and removed from the Air Force on allegations that he abused his then-wife and a child. The following year, deputies were called to his home to investigate a domestic violence complaint, and he was accused of misdemeanor animal cruelty in Colorado.

The records released Friday include a handwritten statement from the woman who accused Kelley of sexual assault. She wrote that Kelley pinned her down in his room at his parents' home on June 15, 2013.

"He told me would hurt me when I didn't do what he said," she wrote.

Devin Kelley in an undated driver's license photo. Texas Department of Public Safety

The statement is dated June 18, 2013. The records also include a signed complaint agreement to press charges that included a warning that making a false statement was a crime.

Her signature is blacked out on the agreement, as are any references to her name. But the records also include a statement from Kelley's first wife, Tessa Brennaman, who said the alleged victim told her about the incident a day later, on June 16, 2013.

Related: Texas gunman escaped from mental health facility in 2012

Brennaman also said Kelley abused her repeatedly during their marriage, including slapping and choking her, and even "water-boarded" her. Their divorce was finalized in October 2012, according to court records.

But the released records also include Comal County detective Chris Garza's timeline of the case that says he left three voicemails for the alleged victim between July 2013 and September 2013. The records don't indicate whether he tried to visit her in person.

In an Oct. 7, 2013, letter, Garza told the victim that she had not returned his messages and that he needed her cooperation. "I cannot proceed without your help," Garza wrote.

Maria Durand leans over while hanging onto two of the twenty six crosses representing the twenty six victims in Sutherland Springs, Texas, on Nov. 7, 2017. LARRY W. SMITH / EPA

According to Garza's timeline, the case was "inactivated pending contact from the victim." The Comal County district attorney's office has said no case was filed with prosecutors.

Reynolds said Friday that deputies eventually spoke to the victim in October. Garza then tried to contact Kelley, but was unsuccessful, and that the investigation "stalled," Reynolds said.

Kelley should have been arrested the following year, Reynolds said. But the sheriff's office did not have a case-tracking database that would have warned deputies responding to a domestic disturbance that Kelley was the subject of a sexual assault investigation. Reynolds, who took office as sheriff last year, said he is now creating such a database.

Phone numbers listed for Kelley's parents were out of service.

The Air Force has also said it failed to report Kelley's court-martial — and the resulting sentence of 12 months' confinement — to the FBI, which keeps criminal history records in databases used to conduct background checks of gun buyers.