The attacker was killed by a Border Patrol agent who rushed into the school without waiting for backup, according to a law enforcement official.
Tuesday's assault at Robb Elementary School in the heavily Latino town of Uvalde was the deadliest shooting at a U.S. school since a gunman killed 20 children and six adults at Sandy Hook Elementary in Newtown, Connecticut, in December 2012.
Hours after the attack, families were still awaiting word on their children. At the town civic center where some gathered, the silence was broken repeatedly by screams and wailing. ``No! Please, no!'' one man yelled as he embraced another man.
``My heart is broken today,'' said Hal Harrell, the school district superintendent. ``We're a small community, and we're going to need your prayers to get through this.''
Gov. Greg Abbott said one of the two adults killed was a teacher.
Adolfo Cruz, a 69-year-old air conditioning repairman, was still outside the school as the sun set, seeking word on his 10-year-old great-granddaughter, Eliajha Cruz Torres.
He drove to the scene after receiving a terrifying call from his daughter shortly following the first reports of the shooting. He said other relatives were at the hospital and the civic center.
Waiting, he said, was the heaviest moment of his life.
``I hope she is alive,'' Cruz said.
The attack was the latest grim moment for a country scarred by a string of massacres, coming just 10 days after a deadly, racist rampage at a Buffalo, New York, supermarket. And the prospects for any reform of the nation's gun regulations seemed as dim, if not dimmer, than in the aftermath of the Sandy Hook deaths.
But President Joe Biden appeared ready for a fight, calling for new gun restrictions in an address to the nation hours after the attack.
``As a nation we have to ask, when in God's name are we going to stand up to the gun lobby? When in God's name are we going to do what has to be done?'' Biden asked. ``Why are we willing to live with this carnage?``
It was not immediately clear how many people in all were wounded, but the school district's police chief, Pete Arredondo, said there were ``several injuries.''
Staff members in scrubs and devastated victims' relatives could be seen weeping as they walked out of Uvalde Memorial Hospital, which said 13 children were taken there. Another hospital reported a 66-year-old woman was in critical condition.
Officials did not immediately reveal a motive, but they identified the assailant as Salvador Ramos, a resident of the community about 85 miles (135 kilometers) west of San Antonio. Law enforcement officials said he acted alone.
Uvalde, home to about 16,000 people, is about 75 miles (120 kilometers) from the border with Mexico. Robb Elementary, which has nearly 600 students in second, third and fourth grades, is in a mostly residential neighborhood of modest homes.
The attack came as the school was counting down to the last days of the school year with a series of themed days. Tuesday was to be ``Footloose and Fancy,'' with students wearing nice outfits.
Ramos had hinted on social media that an attack could be coming, according to state Sen. Roland Gutierrez, who said he had been briefed by state police. He noted that the gunman ``suggested the kids should watch out,'' and that he had bought two ``assault weapons'' after turning 18.
Before heading to the school, Ramos shot his grandmother, Gutierrez said.
Other officials said that the grandmother survived and was being treated, though her condition was not known.
Investigators believe Ramos posted photos on Instagram of two guns he used in the shooting, and they were examining whether he made statements online in the hours before the assault, a law enforcement official said.
Law enforcement officers were serving multiple search warrants Tuesday night and gathering telephone and other records, the official said. Investigators were also attempting to contact Ramos' relatives and were tracing the firearms.
The official could not discuss details of the investigation publicly and spoke to The Associated Press on condition of anonymity.
The attack began about 11:30 a.m., when the gunman crashed his car outside the school and ran into the building, according to Travis Considine, a spokesman for the Texas Department of Public Safety. A resident who heard the crash called 911, and two local police officers exchanged gunfire with the shooter.
Both officers were shot. It was not immediately clear where on the campus that confrontation occurred or how much time elapsed before more authorities arrived on the scene.
One Border Patrol agent who was working 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 authorized to talk about it.
The agent was wounded but able to walk out of the school, the law enforcement official said.
Meanwhile, teams of Border Patrol agents raced to the school, including 10 to 15 members of a SWAT-like tactical and counterterrorism unit, said Jason Owens, a top regional official with the Border Patrol.
He said some area agents have children at Robb Elementary.
``It hit home for everybody,`` he said.
Condolences poured in from leaders around the world. Pope Francis pleaded that it was time say ``'enough' to the indiscriminate trade of weapons!'' Foreign Minister Dmytro Kuleba of Ukraine, which is at war with Russia after Moscow invaded, said that his nation also knows ``the pain of losing innocent young lives.''
The tragedy in Uvalde was the deadliest school shooting in Texas history, and it added to a grim tally in the state, which has been the site of some of the deadliest shootings in the U.S. 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 targeting Hispanics.
The shooting came days before the National Rifle Association annual convention was set to begin in Houston. Abbott and both of Texas' U.S. 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 lawmakers to change U.S. gun policies in any significant way have consistently faced roadblocks from Republicans and the influence of outside groups such as the NRA.
A year after Sandy Hook, Sens. Joe Manchin, a West Virginia Democrat, and Patrick J. Toomey, a Pennsylvania Republican, negotiated a bipartisan proposal to expand the nation's background check system. But the measure failed in a Senate vote, without enough support to clear a 60-vote filibuster hurdle.
Last year, the House passed two bills to expand background checks on firearms purchases. One bill would have closed a loophole for private and online sales. The other would have extended the background check review period. Both languished in the 50-50 Senate, where Democrats need at least 10 Republican votes to overcome objections from a filibuster.