Police and SWAT team members swarmed the campus and began clearing students from the school in Parkland, about an hour north of Miami, as parents and ambulances converged on the scene.

Image copyrightGetty ImagesImage caption Video footage from the scene showed students being evacuated in small groups

Mr Cruz, who had been expelled for “disciplinary reasons”, was taken into custody without incident in the nearby town of Coral Springs about an hour after he left the high school, according to police.

“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,” Sheriff Israel said.

“Just a horrible day for us,” said Robert Runcie, the superintendent of the county’s school district.

‘Worst nightmare’

Many students said they thought it was a drill after hearing the fire alarm go off shortly before the shooting.

Students told US media they hid under desks, in closets or barricaded doors as loud shots rang out.

One student, Bailey Vosberg, said: “I heard what sounded like fireworks and I looked at my friend and he asked me if I heard that.”

“Immediately, I knew. I didn’t say anything to him, I just hopped over the fence and I went straight to the road that our school is located on – and as I got there there was just Swat cars and police units, police vehicles just flying by, helicopters over the top of us.”

Image copyrightEPAImage caption Students were reunited with parents at a nearby “staging area” in Coral Springs

Caesar Figueroa, a parent, told CBS News his daughter was hiding in a closet when she called him.

He told the news outlet earlier that he told her not to call him because he did not want the gunman to hear her voice.

“It’s the worst nightmare not hearing from my daughter for 20 minutes, it was the longest 20 minutes of my life,” Mr Figeuroa said.