Broward County Sheriff Scott Israel identified the gunman as Nikolas Cruz, 19, a former student at Marjory Stoneman Douglas High School in Parkland who had been expelled for "disciplinary reasons."
Cruz was arrested without incident in the nearby town of Coral Springs after the Valentine’s Day rampage and taken to hospital with minor injuries, the sheriff said.
"We have already begun to dissect his websites and things on social media that he was on and some of the things... are very, very disturbing," Israel said.
"He had countless magazines, multiple magazines, and at this point, we believe he had one AR-15 rifle," the sheriff added.
Israel said both students and adults had been killed. He was uncertain about the exact number of people injured, but at least 14 were taken to hospital and two had died there of their wounds.
The shooting, one of nearly 20 since the start of the year, will once again throw the spotlight on the epidemic of gun violence in the United States and the ready accessibility of weapons in a country with 33,000 gun-related deaths annually.
"This is a terrible day for Parkland," Israel said, speaking of the city of about 30,000 people, located 50 miles (80 kilometres) north of Miami.
"My very own triplets went to that school."
A teacher at the school told The Miami Herald that Cruz had been identified previously as a potential threat to his classmates.
"We were told last year that he wasn’t allowed on campus with a backpack on him," math teacher Jim Gard said. "There were problems with him last year threatening students, and I guess he was asked to leave campus."
Cruz was also said to have been in the Junior ROTC (Reserve Officers’ Training Corps) program while at school.
A law enforcement source told CBS News that the gunman pulled a fire alarm before opening fire, but Israel said he could not confirm that report.
’Everyone started running’
Parkland Mayor Christine Hunschofsky told CNN she had spoken to a number of students after the shooting erupted shortly after 2:00 pm (1900 GMT).
"They were very scared," she said. "And almost in shock when they came out."
Television images showed students, some with their hands in the air, being led out of the school by heavily armed police officers and an armoured vehicle filled with a SWAT team on the scene.
Student Jeiella Dodoo told CBS News that she and her schoolmates had evacuated their classroom calmly after hearing what they thought had been a routine fire alarm.
"The alarm went off so we had to evacuate from our classes," she said.
"Then we heard gunshots.
"I heard about six gunshots," she said, "and then some people started running and then everyone started running because we were like ’If it’s real, then just run.’"
Teacher Melissa Falkowski told US networks that she had helped 19 students squeeze into a closet with her.
"We were in there for probably 40 minutes. We were locked in the closet until SWAT came and got us," she told CNN.
Police officers in helmets, bulletproof vests and armed with automatic weapons could be seen stationed at several points around the sprawling school complex, which serves nearly 3,000 students.
"Just a horrible day for us," said the superintendent of the county’s school district, Robert Runcie.
"This is very sad to me and our family too," 61-year-old Joseph Panikulangara, whose 17-year-old niece Dhiya attends the school, told AFP.
The FBI said it was assisting local law enforcement with the investigation.
When asked about security, Hunschofsky said a police officer is always stationed at the school and there was a "single point of entry."
No child should ’feel unsafe’
President Donald Trump offered his "prayers and condolences to the families of the victims.
"No child, teacher or anyone else should ever feel unsafe in an American school," he said on Twitter.
Since the December 2012 massacre at the Sandy Hook Elementary School in
Newtown, Connecticut, where 20 children and six adults were shot dead, warning procedures and emergency drills have multiplied at US schools.
But since January 2013, there have been at least 291 school shootings across the country -- an average of about one a week, according to Everytown for Gun Safety, a non-profit group that advocates for gun control.
"It is pretty clear that we’re failing our kids here," said Falkowski, the teacher who helped shield her students from harm in a closet.
"I’m not saying the solution is one thing or another, but this does not happen in other countries the way it happens here." VNS