Salvador Ramos, 18, used a semi-automatic rifle use to shoot pupils at Robb Elementary School in Uvalde.
He had legally bought two such rifles just days before the attack, soon after his 18th birthday, authorities said.
About 30 minutes before the bloodbath, Ramos made three social media posts, Governor Gregg Abbot said.
According to the governor, Ramos posted that he was going to shoot his grandmother, then that he had shot the woman, and finally that he was going to shoot up an elementary school.
Mr Abbott said Ramos, a resident of the community about 85 miles west of San Antonio, had no known criminal or mental health history.
Seventeen people were injured in the attack.
“Evil swept across Uvalde yesterday. Anyone who shoots his grandmother in the face has to have evil in his heart,” Mr Abbott said at a news conference.
“But it is far more evil for someone to gun down little kids. It is intolerable and it is unacceptable for us to have in the state anybody who would kill little kids in our schools.”
Democrat Beto O’Rourke, who is running against Mr Abbott for governor this year, interrupted the news conference, calling the Republican’s response to the tragedy “predictable”.
Mr O’Rourke was escorted out while members of the crowd yelled at him.
As details of the latest mass killing to rock the US emerged, grief engulfed the small town of Uvalde, which has a population of 16,000.
The dead included an outgoing 10-year-old, Eliahna Garcia, who loved to sing, dance and play basketball; a fellow fourth grader, Xavier Javier Lopez, who had been eagerly awaiting a summer of swimming; and a teacher, Eva Mireles, with 17 years’ experience whose husband is an officer with the school district’s police department.
“I just don’t know how people can sell that type of a gun to a kid 18 years old,” Eliahna’s aunt Siria Arizmendi said angrily through tears. “What is he going to use it for but for that purpose?”
Christopher Olivarez, of the Texas Department of Public Safety, told CNN that all of those killed were in the same fourth-grade classroom.
The killer “barricaded himself by locking the door and just started shooting children and teachers that were inside that classroom”, Mr Olivarez said. “It just shows you the complete evil of the shooter.”
Law enforcement officers eventually broke into the classroom and killed the gunman. Police and others responding to the attack also went around breaking windows at the school to enable students and teachers to escape.
The attack in the predominantly Latino town of Uvalde was the deadliest school shooting in the US since a gunman killed 20 children and six adults at Sandy Hook Elementary in Newtown, Connecticut, in December 2012.
The bloodshed was the latest in a seemingly unending string of mass killings at churches, schools, stores and other sites in the United States. Just 10 days earlier, 10 black people were shot to death in a racist rampage at a Buffalo supermarket.
In a sombre address to the nation hours after the attack in Texas, President Joe Biden pleaded for Americans to “stand up to the gun lobby” and enact tougher restrictions, saying: “When in God’s name are we going to do what has to be done?”
But the prospects for any reform of the nation’s gun regulations appeared dim. Repeated attempts over the years to expand background checks and enact other curbs have run into Republican opposition in Congress.
On the day Ramos bought his second weapon last week, an Instagram account that investigators say apparently belong to Ramos carried a photo of two AR-style rifles.
Ramos apparently tagged another Instagram user, one with more than 10,000 followers, asking her to share the picture with her followers.
“I barely know you and u tag me in a picture with some guns,” replied the Instagram user, who has since removed her profile. “It’s just scary.”
On the morning of the attack, the account linked to the gunman replied: “I’m about to.”
Instagram confirmed to The Associated Press that it is working with law enforcement to review the account but declined to answer questions about the postings.
Investigators are also looking at an account on TikTok, possibly belonging to the shooter, with a profile that reads: “Kids be scared IRL,” an acronym meaning “in real life”.
Officers found one of the rifles in Ramos’ truck and the other in the school, according to the briefing given to lawmakers.
Ramos was wearing a tactical vest but it had no hardened body-armour plates inside, lawmakers were told. He also dropped a backpack containing several magazines full of ammunition near the school entrance.
One of the guns was purchased at a federally licensed dealer in the Uvalde area on May 17, according to state Senator John Whitmire, who was briefed by investigators. Ramos bought 375 rounds of ammunition the next day, then purchased the second rifle last Friday.
On Tuesday morning, Ramos shot and wounded his grandmother, then fled the scene, crashing his truck near the school and entering the building, authorities said.
Dillon Silva, whose nephew was in a nearby classroom, said students were watching the Disney movie Moana when they heard several loud pops and a bullet shattered a window. Moments later, their teacher saw the attacker stride past the door.
“Oh, my God, he has a gun!” the teacher shouted twice, according to Silva. “The teacher didn’t even have time to lock the door,” he said.
A tactical team forced its way into the classroom where the attacker was holed up and was met with gunfire from Ramos but shot and killed him, according to Mr Olivarez.
In the aftermath, families in Uvalde waited hours for word on their children.
At the town civic centre where some gathered Tuesday night, the silence was broken repeatedly by screams and wails. “No! Please, no!” one man yelled as he embraced another man. On Wednesday morning, volunteers were seen arriving with bibles and therapy dogs.