The 17-year-old was in environmental science class at Marjory Stoneman Douglas High School, Florida. The teacher had just passed out worksheets.
When he heard the bang, his classmates turned to each other. That sounded like a gun, they said.
The teacher closed the door. Within seconds, the fire alarm went off.
"We instinctively walked outside," says David. "We thought it was a drill."
As David's class walked towards the evacuation zone, they saw a "tsunami" of people running towards them. They turned and followed the crowd down the corridor.
What they didn't realise was this: they were heading towards the shooter.
"A very heroic janitor stopped us," says David. "He said, 'Don't go that way - he [the shooter] is over there'."
After they turned round, Ashley Kurth - the teacher in charge of the culinary programme, known in school as Chef Kurth - funnelled the crowd into her own classroom.
"Within 30 seconds she easily had 30 or 40 people in there," says David. The lights were switched off.
One girl had a panic attack, and was given water. But, says David, most people were "relatively calm".
Then news of the shooting filtered through on their phones.
David's younger sister is also a student at Stoneman Douglas. "I knew she was alive - at least in the beginning," he says.
"I had a text from her, and a call. She was very frantic. I was petrified but I knew she was on the other side of the school [away from the shooter]."
David called his dad, a former FBI agent, who told him to stay calm. Other pupils called their parents, saying they loved them.
But, says David, there wasn't much crying. "There was a group energy that kept us strong. There was a melancholy calm."
David is a student journalist, so started interviewing people, using his phone to record them.
"I figured, if I died, at least this [the recording] would be passed on to other people, so these voices would echo on."
David tried to stay calm and help others. The classroom had two doors: if the shooter entered one, he thought, they could escape through another.
But he knew that might not be enough. "I realised I may not survive," he says. "It was going through everybody's minds at some point."
After around an hour, five members of a police Swat team burst into the classroom. They told people to get down, and put their hands up.
When they were allowed to stand up, they walked out of the classroom, then started running. Their hands were still in the air.
"At this time, they hadn't eradicated the suspect," says David. "We didn't know that, but they didn't have him. We were quite frankly running for our lives."
When he reached safety, David says he felt "shock - pure shellshock". He found his dad, and his sister. One of her friends was killed.
In the early hours of Thursday, David was still outside the school where 17 people died hours earlier.
"I feel a mix of anger, sadness, but mostly passion," he says.
"I don't want this to ever happen to anyone else again. The fact is there are 17 families that now have empty rooms…
"These are people's kids. They've poured all the love, everything they could ever get, into these kids. And it's all been taken by one piece of metal, and bled out onto the floor."