Florida man Nikolas Cruz has been charged with 17 counts of premeditated murder after one of the deadliest school shootings in US history.
The ex-student, identified as Nikolas Cruz, walked into the Marjory Stoneman Douglas High School in Parkland, about 72km north of Miami on Wednesday.
He then pulled a fire alarm, prompting students and staff to pour from classrooms into hallways, according to Florida's two US senators, who were briefed by federal authorities.
He then opened fire on students and teachers, killing 17 people, Broward County Sheriff Scott Israel said. Fifteen wounded survivors are still in hospital, five of them in critical condition.
Police believe he acted alone.
He was questioned for hours by state and federal authorities before being charged this morning.
Cruz participated in the activities of a Florida white nationalist militia, the group's leader said on Thursday.
"He had some involvement with the Clearwater Republic of Florida cell at some point," Jordan Jereb said in a telephone interview.
The authorities have so far offered no details about his possible motive, except to say that he was expelled from the high school last year.
Cruz was armed with an AR-15 style rifle, smoke grenades, gas mask and multiple ammunition magazines when he surrendered to officers in a nearby residential area, police said.
Police and former classmates said he loved guns and was expelled for unspecified disciplinary reasons.
He was expected to appear in court on Thursday afternoon for a bond hearing, Constance Simmons, a spokeswoman for the state attorney's office, said.
RNZ correspondent Steve Mort, who is at the school where the shooting took place, said students described Cruz as "abusive" and a "loner".
"But it is going to take a long time to piece together exactly why he may have carried out such an attack."
Mort said the FBI were aware of some warning signs about Cruz based on social media posts but US media report that these concerns were not passed onto local and state law enforcement officials.
A federal law enforcement official has told Reuters the FBI was conducting an extensive review of how it handled the tip to see if mistakes were made.
Trump focuses on 'mental health', avoids gun control debate
The Florida shooting stirred the long-simmering US debate on the right to bear arms, which is protected by the Second Amendment of the US Constitution.
Schools across the country have installed electronically secured doors and added security staff, but few legislative solutions have emerged.
The attack was the 18th in a US 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.
US President Donald Trump called on Thursday for healing and peace a day after the attack.
He did not address the issue of gun control, saying his administration would work to improve school safety and address mental illness.
"We must also work together to create a culture in our country that embraces the dignity of life that creates deep and meaningful human connections," Mr Trump said at the White House, adding that he planned to visit victims and local authorities in Parkland, Florida, at a later date.
He did say that making schools safer would be the administration's top priority and that people needed to work together to change US culture to "embrace life" and "build connections".
Earlier on Twitter, he said there were "so many signs that the Florida shooter was mentally disturbed, even expelled from school for bad and erratic behavior".
"Neighbors and classmates knew he was a big problem. Must always report such instances to authorities, again and again!"
It was the second-deadliest shooting in a US public school after the 2012 massacre of 20 first-graders and six educators at Sandy Hook Elementary in Newtown, Connecticut.
The deadliest school shooting in US history was at Virginia Tech in 2007, when 32 people were killed.
'I'm going to be a school shooter' - FBI was tipped off
The FBI has confirmed it investigated last year after the teenager reportedly left a comment on a YouTube video last year stating: "I'm going to be a professional school shooter."
It said it couldn't confirm who left the comment. The man who posted the video was alarmed and contacted the FBI, Buzzfeed reported.
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," Lewis told CNN.
FBI special agent in charge Robert Lasky told reporters on Thursday the bureau received the 2017 tip but said investigators had been unable to locate the person who made the comment.
"No other information was included with that comment which would indicate a time location or the true identity of the person who made the comment," Mr Lasky said.
South Florida remained on edge on Thursday. Miami's main criminal courthouse building was put into lockdown after an unspecified threat was reported, Miami-Dade County's state attorney said on Twitter.
Another Broward school briefly also went into lockdown after reports of a shooting, which turned out to be unfounded, local media reported.