Gov. Greg Abbott of Texas confirmed the death toll, which has steadily increased throughout the day after the shooting at the First Baptist Church of Sutherland Springs. A pregnant woman and children were among the dead.
At least 20 people were also injured. Their conditions ranged from “minor to very severe,” law enforcement officials said at a news conference on Sunday evening.
Among those killed, 23 people died inside the church, two outside the building and one person after being transported to a hospital. The ages of the wounded and dead ranged from 5 to 72, the authorities said.
Two law enforcement sources, who spoke on the condition of anonymity because of the continuing investigation, identified the gunman as Devin P. Kelley, 26. The gunman parked at a gas station near the church, exited the vehicle and began shooting outside the church before entering the building’s right side, firing all the while, the authorities said.
Representative Henry Cuellar of Texas, who said he was briefed by law enforcement authorities, said the gunman came from Comal County, which is northeast of San Antonio. “He went there, he walked in, started shooting people and then took off,” he said.
Outside the church after the shooting, a resident shot at the man with a rifle, and the gunman dropped his rifle, a spokesman at the Texas Department of Public Safety, Freeman Martin, said at the news conference.
The person pursued the gunman, who fled north to Guadalupe County, where his car crashed. He was found dead in the car with a fatal gunshot wound, the authorities said. They said they did not know who fired the fatal shot.
Albert Gamez Jr., a Wilson County commissioner, told CNN Sutherland Springs is a small community where everyone knows one another.
He said: “You never expect something like this. My heart is broken.”
Hours after the shooting, the one-story rectangular church remained sealed off, with yellow tape posted along the church grounds. Reporters poured into Sutherland Springs throughout the day as the tragedy transformed the once-obscure Texas farming community into the scene of the latest mass killing.
The unincorporated community has a population that numbers in the low hundreds — the 2000 census was 362, according to the Texas State Historical Association. The preliminary death toll would amount to about 7 percent of the population.
The service at the church last Sunday, which was posted on YouTube, began with a rendition of a song called “Happiness Is the Lord.”
Then the pastor, Frank Pomeroy, told his parishioners — 20 to 30 were visible in the video — to walk around the room and “shake somebody’s hand.”
“Tell them it’s good to see them in God’s house this morning,” he said.
Videos posted online show lyrics to the hymns appearing on television screens with parishioners playing electric guitars and a sign language interpreter translating the songs.
Scott Holcombe and Sarah Slavin said their parents, Bryan and Karla Holcombe, were among the dead. Sobbing on a curb outside Connally Memorial Medical Center in Floresville, about 15 miles from Sutherland Springs, Scott Holcombe said: “I’m dumbfounded. This is unimaginable.”
He added: “My father was a good man and he loved to preach. He had a good heart. They knew where they were going. There’s peace in that.”
A parishioner, Sandy Ward, said in an interview on Sunday that a daughter-in-law and three of her grandchildren were shot. Her grandson, who is 5, was shot four times and remained in surgery as of Sunday night. She said she was awaiting word on her other family members.
Ms. Ward said she did not attend services on Sunday because of her troubled knees and a bad hip. “I just started praying for everybody who was there” when she learned of the shooting, she said.
Eight shooting victims were taken to Brooke Army Medical Center in San Antonio, the hospital said.
Joseph Silva, 49, who lives about five miles northeast of Sutherland Springs, said the police had instructed his family and neighbors to stay indoors.
In a phone interview on Sunday afternoon, he described Sutherland Springs as “a one-blinking-light town.”
“There is a gas station and a post office,” he said. “That’s about all there really is.”
Mr. Silva said he had been approached by a woman who said she had two loved ones at the church who were shot.
“There are a number of individuals just weeping and just wanted to know what’s happened to their loved ones,” he said. “Everybody is pretty grief-stricken. Everyone’s worried.”
The First Baptist Church of La Vernia, Tex., about seven miles away, wrote on Facebook that it would open its doors from 5 to 7 p.m.
“Today an unthinkable tragedy occurred in our community,” the church wrote. “There will be pastors and leaders present to pray with you or to talk, and the altar will be open for us to fall at the feet of Jesus.”
A spokeswoman for the F.B.I.’s San Antonio field office confirmed that the agency is on the scene in Sutherland Springs helping the Texas Rangers, who are leading the investigation. The spokeswoman, Michelle Lee, said that the F.B.I. expects other agencies to join the effort on Sunday, but that it was common for the Rangers to take the lead in a crime scene of this scale in a rural area.
President Trump, who was in Japan on a trip to several Asian countries, offered his support.