Police entered Robb Elementary within four minutes but fell back as they took fire.
UVALDE, Texas -- A small town in rural Texas is reeling after a gunman opened fire at an elementary school on Tuesday, killing 19 children.
Two teachers were also among those killed at Robb Elementary School in Uvalde, according to authorities.
Prior to opening fire at the school, the suspect also allegedly shot his grandmother, officials said.
The alleged gunman -- identified by authorities as 18-year-old Salvador Ramos, a student at Uvalde High School -- is dead.
Joe Biden and first lady Jill Biden will visit Uvalde Sunday to grieve with the community after the attack that the president decried as "carnage" in a call for lawmakers "to act."
On Tuesday morning, Ramos shot his 66-year-old grandmother in the head at their residence, and she was able to run across the street and call police, Steve McCraw, director of the Texas Department of Public Safety, said. She was taken to the hospital via helicopter and is still in critical condition, he said.
Ramos drove about 2 miles to Robb Elementary in his grandmother's truck crashing the vehicle outside the school, McCraw said. He exits the vehicle with a backpack and rifle, authorities said.
Even though the school doors were supposed to be locked during the day, it appears the door the gunman entered through was unlocked, Victor Escalon, the Texas Department of Public Safety's regional director for south Texas, said at a press conference Thursday. Police did not confront the gunman before he entered the school, despite earlier reporting that a school district police officer had confronted the gunman.
The suspect then saw two witnesses at the funeral home across the street from where he crashed his car and opened fire on them. Neither person was struck.
While in the parking lot, the gunman fired shots at the school multiple times. The suspect then walked into the west side of the building, Escalon said.
The Uvalde Police Department and the Independent School District Police Department attempted to enter the school building four minutes later, but they heard gunfire and took rounds so they moved back, took cover and called for additional resources, Escalon said.
Escalon said the officers "don't make entry initially because of the gunfire they're receiving. But we have officers calling for additional resources."
At one point, students heard banging on a window before their teacher saw the shooter with a "big gun," a fourth-grade student who was inside the school at the time said in an interview with ABC News, describing the "nonstop" gunshots that followed. After Ramos entered the school through a back door, he went into a classroom that was connected internally to a second classroom and began shooting, authorities said.
Law enforcement then converged into the classroom and Ramos was shot and killed by an officer, authorities said. He was killed roughly an hour after arriving at the school.
For responding officers, including Border Patrol Agents, this was personal. Many had their own children in harm's way.
At least one agent with the elite Border Patrol Tactical Unit shot the gunman, although it's unclear who among them killed him, the official said.
"Risking their own lives, these Border Patrol Agents and other officers put themselves between the shooter and children on the scene to draw the shooter's attention away from potential victims and save lives," Marsha Espinosa, the Assistant Secretary of Public Affairs at the Department of Homeland Security, tweeted.
The mother of the 18-year-old gunman told ABC News in an interview that her son was "not a monster," but that he could "be aggressive."
"I had an uneasy feeling sometimes, like 'what are you up to?" Adriana Reyes told ABC News' Chief National Correspondent Matt Gutman in an interview at her home. "He can be aggressive... If he really got mad."
WATCH: Mother of Texas school shooting suspect speaks out; new text messages raise questions
Ramos turned 18 nine days ago and allegedly purchased an AR-15-style rifle just one day after his birthday. Three days later, he bought a second one, and four days after that, he used them to carry out the second-deadliest school shooting in U.S. history, authorities said.
Ramos' grandfather told Gutman he didn't know his grandson had weapons.
"If I would have known, I would have reported it," Rolando Reyes said.
Messages obtained by ABC News also reveal a chilling warning just minutes before the shooting.
Moments before carrying out the deadly attack at Robb Elementary, Ramos allegedly sent a string of messages to a young girl he met online, detailing that he had shot his grandmother and was heading to the school for his next target, according to messages reviewed by ABC News.
The messages allegedly show Ramos texting with a 15-year-old in Germany who he met on the social media platform Yubo, describing an argument he was having with his grandmother over a phone bill before texting, "I shot my grandmother in the head" and "ima go shoot up a elementary school rn."
"She's on the phone with AT&T," Ramos allegedly wrote at 11:06 a.m., while referring to his grandmother with a derogatory term.
"Ima do something to her rn," he said in another alleged message. Minutes later, the gunman allegedly wrote, "I shot my grandmother in the head" before immediately adding "ima go shoot up a elementary school rn."
The friend did not reply to the accused gunman's messages until news broke regarding the shooting, according to the screenshot reviewed by ABC News. Law enforcement sources tell ABC News the messages are part of the ongoing investigation into the shooter.
Ramos also allegedly committed animal abuse and displayed videos of the cruelty to users on a social media platform, according to two users who spoke to ABC News.
In some instances, the alleged animal abuse was committed in public and then posted for online viewing, and Ramos allegedly boasted about how he and his friends did it "all the time," according to one user.
The allegations of animal abuse are similar to what authorities have learned about Payton Gendron, the white 18-year-old suspect in who allegedly committed the May 14 racially motivated mass shooting at a Buffalo supermarket that left 10 Black people dead.
A fourth-grade teacher, several sets of cousins and a 10-year-old boy whose family called him "the life of the party" were among those killed in a mass shooting at a Texas elementary school on Tuesday, ABC News has learned.
"When parents drop their kids off at school, they have every expectation to know that they're going to be able to pick their child up when that school day ends. And there are families who are in mourning right now," Gov. Greg Abbott told reporters.
ABC News has confirmed the identities of the following victims:
TAKE ACTION: Resources for survivors and victims of gun violence
The school superintendent ended the school year early in light of the massacre.
"My heart was broken today. We're a small community and we will need your prayers to get us through this," Dr. Hal Harrell, the district superintendent, said.
The Uvalde school shooting joins the grim ranks of nearly a dozen other mass shootings that have taken place at music festivals, nightclubs and other schools in the past nearly quarter-century in America's unparalleled gun violence epidemic.
The incident makes it the second-deadliest shooting at an elementary, middle or high school in U.S. history -- behind the Sandy Hook Elementary School shooting in 2012 -- and the seventh-deadliest shooting in the country since the Columbine High School massacre in 1999.
Tuesday's horror comes on the heels of yet another deadly mass shooting in Buffalo, New York, and amid a rapid rise in active shooter incidents across the country.
These are the mass shootings with the highest death tolls in recent American history, based on an ABC News analysis.