The gunman sent a direct message to an Instagram user, saying he planned to attack a school, law enforcement sources say.
UVALDE, Texas -- Uvalde High School student Salvador Ramos allegedly purchased two assault rifles just days after turning 18 and used them to carry out the second-worst school shooting in U.S. history -- all within a span of eight days, authorities said.
Ramos was known for fighting and threatening fellow students, some classmates told ABC News. He allegedly exhibited unusual behavior such as threatening classmates and claiming to have cut scars into his face, classmates said.
Twenty-one people, including 19 third and fourth grade children, were killed in the attack, law enforcement officials said. Two teachers were killed, too. Another 17 people were wounded, including three law enforcement officers.
MORE: What we know about 21 Texas school shooting victims; teacher's widower dies of heart attack
This is how the shooting unfolded:
Salvador Ramos asks his sister to purchase him a gun. She flatly refuses.
In a four-person group chat on Instagram, Ramos discussed being a school shooter.
In a four-person group chat on Instagram, Ramos discusses buying a gun.
In a four-person group chat on Instagram, a user says to Ramos, "word on the street is you're buying a gun." Ramos replied, "Just bought something. RN."
Ramos posts on Instagram, "10 more days." A user replied, "are you going to shoot up a school or something?" Ramos responds, "No. And stop asking dumb questions. You'll see."
A young girl in Germany, referred to as "Cece," meets Ramos on Yubo, a social media app described as a dating app for teens. The two begin a dialogue and exchange cell phone numbers, Cece told ABC News.
Ramos turns 18, according to the Bureau of Alcohol, Tobacco, Firearms and Explosives.
Ramos buys a semi-automatic rifle at a local sporting goods store called Oasis Outback, McCraw said.
Ramos purchases 375 rounds of ammunition for that rifle, McCraw said. It is not known where he purchased that ammunition.
Ramos purchases another semi-automatic rifle, again at Oasis Outback.
Sometime Tuesday morning - An Instagram account that law enforcement sources tell ABC News they believe is connected to Ramos sent another user on the social media platform a photo of a gun lying on a bed, according to a user who shared direct messages from the suspect's alleged account with ABC News.
Sometime around 11:00 a.m. - Ramos allegedly sends text messages to Cece, the young girl in Germany whom he met weeks earlier, claiming that he was about to "do something" to his grandmother. Law enforcement sources said these messages are part of the ongoing investigation.
Shortly after 11:00 a.m. - Ramos shoots his grandmother "in the face," according to Steven McCraw, director Texas Dept. of Public Safety, and flees his grandmother's home.
- At some point after shooting his grandmother, Ramos sends another one-to-one message to Cece announcing that he shot his grandmother and was heading to a school, without identifying which school, and saying he planned to attack it.
- Ramos enters his grandmother's vehicle and drives a short distance to Robb Elementary School.
- Ramos' wounded grandmother, still at home, runs across the street to a neighbor's home to report Ramos to the police. She was taken to the hospital via helicopter and is still in stable condition, according to Victor Escalon, South Texas Regional Director of the Department of Public Safety.
11:27 a.m. - A Robb Elementary teacher props open the school's west-facing exterior door.
11:28 a.m. - Ramos crashes his vehicle into a ravine adjacent to Robb Elementary School. He emerges from the passenger side of the vehicle wielding a Daniel Defense AR-15-style assault rifle.
- Ramos wore a backpack containing ammunition and tactical gear, including a vest that could hold ammunition, sources said, but there was no armor or fabric that would protect him from gunfire. Multiple law enforcement sources said Ramos had a total of seven 30-round magazines with him in the classroom where the killing took place. 15 additional loaded magazines were found in his backpack.
- After exiting the vehicle, Ramos fires at two nearby witnesses near a funeral home and then makes his way toward the school.
11:30 a.m. - The teacher inside of Robb reemerges from the same door and calls 911 to report a man with a gun nearby.
11:30 a.m. - U.S. Marshals receive a call from Uvalde Police Department officer requesting assistance in responding to a shooting at Robb Elementary School.
11:31 a.m. - Ramos jumps one fence and approaches the school through a parking lot, firing multiple rounds at the school building. Contrary to previous reporting, Ramos does not encounter any officers outside of the building.
11:31 a.m. - Patrol vehicles arrive at the scene of the funeral home shootings.
11:31 a.m. - A Uvalde ISD officer who is not on campus hears the 911 call about a shooting near the school and immediately drives to the area. The ISD officer approaches a person he believes to be the suspect but is in fact a teacher at the school. In doing so, the ISD officer drives past Ramos, who is crouching behind parked vehicles.
11:32 a.m.- Ramos continues firing multiple rounds at the exterior of the building.
11:33 a.m.- Ramos enters Robb Elementary through its west entrance - the same one propped open by the teacher moments earlier. After entering the building, Ramos walks approximately 20-30 feet before turning right down a corridor. After walking an additional 20 feet, Ramos enters a classroom door to his left.
11:33 a.m. - Ramos enters classroom 111 or 112 and immediately fires more than 100 rounds at students and teachers. The two classrooms are connected internally.
11:35 a.m. - Three Uvalde Police Department officers arrive and enter the school through the same entrance used by Ramos, followed shortly thereafter by three more UPD officers and one county deputy sheriff. A total of seven officers are now inside the school.
- Officers are fired on. Two officers sustain "grazing wounds" from the suspect, who is firing into the hallway from behind a closed door.
11:37 - 11:44 a.m. - Ramos continues firing at intervals.
11:43 a.m. - Robb Elementary posts on Facebook that their campus was under lockdown "due to gunshots in the area."
11:51 a.m. - The police sergeant and additional officers arrive on scene.
11:55 a.m. - 12:00 p.m. - Onlookers gathered outside the school grow restless and encourage officers to enter the building, according to a livestream video posted on social media. At one point, a woman yells, "Get in [there]! I'm gonna go, I'm gonna f***ing go." Moments later, the woman confronts officers again: "it's one person, take him out ... do the parents got to go in there? I'm ready if I have to."
WATCH: Onlookers urged police to charge into Texas school after shooting began, witnesses say
12:03 p.m. - More officers arrive on scene and enter the building. At this point there are 19 law enforcement officers inside the school.
12:03 p.m.- A 911 caller whispers that she is inside of room 112. She remains on the phone for 1 minute and 23 seconds.
12:10 p.m.- The first group of Deputy U.S. Marshals from Del Rio, nearly 70 miles away, arrive on site.
12:10 p.m. - The 911 caller inside of room 112 calls back and reports that multiple people are dead.
MORE: Boy who survived Texas school shooting recalls gunman saying 'you're all gonna die'
12:13 p.m. - The 911 caller inside of room 112 calls back.
12:15 p.m. - U.S. Border Patrol tactical unit members arrive on scene, with shields and other equipment.
12:16 p.m. - The caller inside of room 112 calls back to report that 8 or 9 students are still alive.
12:17 p.m. -- Uvalde Consolidated Independent School District announces the shooting on Twitter.
12:19 p.m.- A new 911 caller who says she is in side room 111 hangs up abruptly when another student tells her to hang up.
12:21 p.m.- Ramos fires again at the classroom door, forcing officers in the building to reposition themselves down the hallway away from the door.
12:21 p.m.- The 911 caller inside room 111 calls back and three gunshots are overheard in the background of the call.
12:30 p.m. - Uvalde Fire Department scanner traffic calls on "additional firemen need to respond to Mill Street to establish a perimeter to assist Uvalde EMS and Uvalde PD, once again we need to respond to South Grove and Mill Street."
12:36 p.m. - The initial 911 caller in room 112, described as a "student child," calls back and is told to stay on the line and be quiet. The caller says "he shot at the door." This call lasts 21 seconds.
12:43 p.m. - The 911 caller inside room 112 asks for police to be sent in.
12:46 p.m. - The 911 caller inside room 112 says she can hear police officers next door.
12:47 p.m. - The 911 caller inside room 112 again asks for police to be sent in.
12:50 p.m. -- Officers breach the classroom door using a set of keys acquired from a school janitor. Officers shoot and kill Ramos in the classroom.
- Immediately after killing Ramos, officers engage in a "rescue operation" to save the remaining children, Escalon said Thursday.
1:06 p.m. - Police announce on social media that the suspected shooter was killed by officers at the scene.
SEE ALSO: Mass shootings in the U.S. have nearly tripled since 2013, data shows