A 19-year-old who had been expelled from his Florida high school was due in court on Thursday, charged with 17 counts of murder, after authorities say he opened fire at the school, unleashing one of the deadliest school shootings in U.S. history.

The ex-student, identified as Nikolas Cruz, walked into the Marjory Stoneman Douglas High School in Parkland on Wednesday and opened fire on students and teachers, Broward County Sheriff Scott Israel said. Police believe he acted alone.

Cruz was expected to appear in court Thursday afternoon for a bond hearing, faced with 17 counts of premeditated murder, said Constance Simmons, a spokeswoman for the state attorney's office.

Cruz was armed with an AR-15-style rifle and had multiple ammunition magazines when he surrendered to officers in a nearby residential area, police said. He loved guns and was expelled for unspecified disciplinary reasons, police and former classmates said.

The shooting in a community about 45 miles (72km) north of Miami was the 18th in a U.S. school this year, according to gun control group Everytown for Gun Safety, continuing a troubling pattern that has played out over the past few years.

It was the second-deadliest shooting in a U.S. public elementary or high school after the 2012 massacre of 20 first-graders and six educators at Sandy Hook Elementary in Newtown, Connecticut.

The deadliest school shooting in U.S. history was at Virginia Tech in 2007, when 32 people were killed.

The Florida shooting stirred the long-simmering U.S. debate on the right to bear arms, which are protected by the Second Amendment of the U.S. Constitution.

Schools across the country have installed electronically secured doors and added security staff, but few legislative solutions have emerged.

"So many signs that the Florida shooter was mentally disturbed, even expelled from school for bad and erratic behaviour," U.S. President Donald Trump said on Twitter on Thursday. "Neighbours and classmates knew he was a big problem. Must always report such instances to authorities, again and again!"

Trump, who ordered flags to fly at half-staff in a sign of mourning, plans to address the nation from the White House at 11am EST (1600 GMT), a spokeswoman said.

"There's more questions than answers," Speaker of the U.S. House of Representatives, Republican Paul Ryan, said in an interview with Indiana radio station WIBC. "I don't think that means you then roll that conversation into taking away citizens' rights."

A law enforcement officer is assigned to every school in the Broward County district, Marjory Stoneman Douglas High board member Donna Korn told a local newspaper. The sheriff's office also provides active shooter training and schools have a single point of entry, she said.

"We have prepared the campuses, but sometimes people still find a way to let these horrific things happen," Korn said.

The first victim of the attack was publicly identified on Thursday as Aaron Feis, an assistant coach on the school's football team and a school security guard who was shot while shielding students, the team said on Twitter.

'THE WORST IN HUMANITY'

Hundreds of panicked students fled the building, running past heavily armed, helmeted police officers while others huddled in closets.

Parents raced to the school of 3,300 students and a nearby hotel that was set up as a checkpoint to find their children.

"This has been a day we’ve seen the worst in humanity," Broward County Public Schools Superintendent Robert Runcie said Wednesday.

The assailant wore a gas mask as he stalked into the school carrying a rifle, ammunition cartridges and smoke grenades, then pulled a fire alarm, prompting students and staff to pour from classrooms into hallways, according to Florida's two U.S. senators, who were brief by federal authorities.

Cruz had recently moved in with another family after his mother's death in November, according to Jim Lewis, a lawyer representing the family and local media, bringing his AR-15 along with his other belongings.

The family believed Cruz was depressed, but attributed that to his mother's death, not mental illness.

"They didn't see any danger. They didn't see any kind of predilection this was going to happen," Lewis told CNN.

Cruz may have left warning signs on social media. Buzzfeed reported that a person named Nikolas Cruz left a comment under a YouTube video that read "I'm going to be a professional school shooter." The man who posted the video was alarmed and contacted the FBI, Buzzfeed reported.

Reuters was unable to immediately confirm those details.

Colton Haab, a 17-year-old junior and member of the Junior Reserve Officer Training Corps at the high school, said he realized the alarms were not a drill after hearing several shots fired and learning that three people had been shot.

"That for me changed it to an active shooter scenario," he said. Haab rushed to his ROTC room and helped usher several dozen students inside, barricading them behind curtains made of Kevlar, a material used to make bullet-proof vests.

"We grabbed two pieces of two-by-four, a fire extinguisher and a chair," Haab said. "If he was going to try to come in the room we were going to try to stop him with whatever we had."