(CNN) A former student unleashed a hail of gunfire in a Florida high school on Wednesday, killing at least 17 adults and children, authorities said.

Florida Gov. Rick Scott ordered government flags flown at half-staff through Monday in honor of victims of the shooting at Marjory Stoneman Douglas High School, a public school of some 3,000 students outside Boca Raton.

The school is closed for the rest of the week, Broward County Public Schools Superintendent Robert Runcie said. The district will offer grief counseling to students and their families.

"This has been a day where we've seen the worst of humanity. Tomorrow is gonna bring out the best in humanity as we come together to move forward from this unspeakable tragedy," he said.

The suspect, 19-year-old Nikolas Cruz , was expelled for unspecified disciplinary reasons, Runcie said. He is due in court Thursday.

"My prayers and condolences to the families of the victims of the terrible Florida shooting. No child, teacher or anyone else should ever feel unsafe in an American school," US President Donald Trump said.

Messages from the scene in texts and Snapchats

Law enforcement responded to reports of a shooting at Marjory Stoneman Douglas High School shortly before 3 p.m. and encountered a chaotic scene.

Investigators believe the suspect pulled the fire alarm to draw people out of classrooms and increase the number of casualties, a law enforcement source told CNN. But the school already had a fire drill earlier in the day, leading some to think it was a false alarm.

Students evacuate the school.

While some left the building, others sought cover in classrooms as the school went into lockdown and the gunman went on his rampage.

Some students, fearing their lives would soon be over, texted goodbyes to loved ones; others used their phones to share startling footage of the carnage on social media.

JUST WATCHED Video shows students hiding as shots are fired Replay More Videos ... MUST WATCH Video shows students hiding as shots are fired 00:39

One teacher said she was on her way out of the building after the fire alarm when another staff member told her the situation was code red -- an active shooter. Melissa Falkowski returned to a classroom and hid in a closet with 19 students from her newspaper class for nearly 40 minutes.

Falkowski credited the fire drill and recent active shooter training with saving lives. And yet, it didn't save enough.

"We could not have been more prepared for this situation, which is what makes it so frustrating," Falkowski told CNN's Anderson Cooper.

"We did everything that we were supposed to do. Broward County Schools has prepared us for this situation and still to have so many casualties, at least for me, it's very emotional. Because I feel today like our government, our country has failed us and failed our kids and didn't keep us safe."

JUST WATCHED Teacher: The government failed us today Replay More Videos ... MUST WATCH Teacher: The government failed us today 00:36

'It's really a blessing to still be alive'

Police are investigating Cruz's digital footprint, Sheriff Scott Israel said. So far, what they've found is "very, very disturbing," he said.

Law enforcement agents transport the suspect in Wednesday's school shooting.

Law enforcement sources said the suspect used a .223 caliber, AR-15 style firearm in the shooting.

Freshman Kayden Hanafi said he heard two gunshots and saw people running out of another building on campus. As he and his classmates went into lockdown, many thought the noise might have been firecrackers.

"It's really a blessing to still be alive," he said.

Nicole Baltzer, 18, said she was in trigonometry class about 10 minutes before the end of the school day when the fire alarm went off. As students evacuated, she heard six gunshots and everyone started running back inside the school, Baltzer said.

"I heard so many gunshots, at least like six. They were very close," Baltzer said.

A police officer told her to close her eyes as she walked past a classroom with broken glass, telling her "there's nothing good to see in there," she said.

A freshman named Aidan posted a photo on social media from inside his math class while on lockdown.

"We have been liberated. God bless, America," Aidan tweeted after being evacuated from the building. "Love each other. You may never know when it may be the last day you meet someone."

The scene inside a classroom at the school.

Terror in Florida's safest city

The shooting sent students and staff streaming out of the school. Some walked calmly with their hands up while others ran. According to a law enforcement source, the suspect initially mixed in with the crowd of students to try to get away, but it didn't work.

Immediately after the shooting, aerial footage from CNN affiliate WSVN showed people lying on the ground outside the school, being treated for injuries and moved to ambulances. Seventeen people, including the suspect, were sent to area hospitals, said Dr. Evan Boyar of Broward Health.

As news of the shooting spread, desperate parents gathered near the property, searching for their children at the nearby Walmart where the students and staff gathered after being evacuated.

Those who died included students and adults, the sheriff said. Twelve were killed inside the building and two died outside, he said. One died in the street and two died at the hospital, Israel said.

Parkland, with a population of 31,000 in 2016, was named Florida's safest city last year , according to one analysis. The south Florida city had seven reported violent crimes and 186 property crimes the previous year, the analysis said.

Clarification: Earlier reports from WSVN said that 20 people may have been injured. CNN has not confirmed the number of injured. This is a developing story and will be updated.