The death toll also included three adults, according to state senator Roland Gutierrez, who said he was briefed by state police on the fatalities. But it was not immediately clear whether that number included the assailant.
It was the deadliest shooting at a US grade school since a gunman killed 20 children and six adults at Sandy Hook Elementary in Newtown, Connecticut, almost a decade ago.
And it came just 10 days after a gunman in body armour killed 10 black shoppers and workers at a supermarket in Buffalo, New York, in what authorities say was a racist attack.
“My heart is broken today,” said Hal Harrell, the school district superintendent, announcing that all school activities were cancelled until further notice.
“We’re a small community and we’re going to need your prayers to get through this.”
The gunman, who was wearing body armour and had hinted on social media of an upcoming attack, crashed his car outside the school and went inside armed, Erick Estrada of the Texas Department of Public Safety told CNN.
He shot his grandmother before heading to the school with two military-style rifles he had purchased on his birthday, Mr Gutierrez said.
“That was the first thing he did on his 18th birthday,” he said.
Federal law enforcement officials said the death toll was expected to rise. They spoke on condition of anonymity because they were not authorised to release investigative details.
The gunman entered Robb Elementary School in Uvalde with a handgun and possibly a rifle, Governor Greg Abbott said.
Officials did not immediately reveal a motive, but the governor identified the assailant as Salvador Ramos and said he was a resident of the heavily Latino community about 85 miles (135 kilometres) west of San Antonio.
A Border Patrol agent who was nearby when the shooting began rushed into the school without waiting for backup and shot and killed the gunman, who was behind a barricade, according to a law enforcement official speaking on condition of anonymity because he was not authorised to talk about it.
The agent was wounded but able to walk out of the school, the law enforcement source said.
Mr Abbott said the gunman was likely killed by police officers but that the events were still being investigated. The school district’s police chief, Pete Arredondo, said that the attacker acted alone.
The massacre of young children was another gruesome moment for a country scarred by an almost ceaseless string of mass killings at churches, schools and stores.
And the prospects for any reform in the nation’s gun regulations seemed at least as dim as in the aftermath of the Sandy Hook deaths.
The gunman in Uvalde “shot and killed, horrifically, incomprehensibly, 14 students, and killed a teacher,” the governor said, adding that two officers were also wounded but were expected to survive.
“Pray for the lost, their families, and Uvalde,” San Antonio mayor Ron Nirenberg said in a tweet.
It was not immediately clear how many people were wounded, but Mr Arredondo said there were “several injuries”.
Earlier, Uvalde Memorial Hospital said 13 children were taken there. Another hospital reported a 66-year-old woman was in critical condition.
Robb Elementary School has an enrolment of just under 600 students, and Mr Arredondo said it serves students in the second, third and fourth grade. He did not provide ages of the children who were shot. This was the school’s last week of classes before summer break.
A heavy police presence surrounded the school on Tuesday afternoon, with officers in heavy vests diverting traffic and FBI agents coming and going from the building.
White House press secretary Karine Jean-Pierre said President Joe Biden was briefed on the shooting on Air Force One as he returned from a five-day trip to Asia.
“When in God’s name are we going to stand up to the gun lobby?” Mr Biden said at the White House on Tuesday evening.
With first lady Jill Biden standing by his side in the Roosevelt Room, Mr Biden added: “I am sick and tired. We have to act.”
Uvalde is home to about 16,000 people and is the seat of government for Uvalde County. The town is about 75 miles (120 kilometres) from the border with Mexico. Robb Elementary is in a mostly residential neighbourhood of modest homes.
The tragedy in Uvalde was the deadliest school shooting in Texas history, and it added to a grim tally of mass shootings in the state that have been among the deadliest in the US over the past five years.
In 2018, a gunman fatally shot 10 people at Santa Fe High School in the Houston area. A year before that, a gunman at a Texas church killed more than two dozen people during a Sunday service in the small town of Sutherland Springs. In 2019, another gunman at a Walmart in El Paso killed 23 people in a racist attack.
The shooting came days before the National Rifle Association (NRA) annual convention was set to begin in Houston.
Mr Abbott and both of Texas’ US senators were among elected Republican officials who were the scheduled speakers at a Friday leadership forum sponsored by the NRA’s lobbying arm.
In the years since Sandy Hook, the gun control debate in Congress has waxed and waned. Efforts by politicians to change US gun policies in any significant way have consistently faced roadblocks from Republicans and the influence of outside groups such as the NRA.