Police surrounded the school, in Parkland, Florida, where the "heavily armed" shooter, wearing a gas mask, pulled out a "long" gun at just after 2pm and began shooting.
At 4pm, two hours after the shooter opened fire, police and Swat teams took him into custody. Police describe him as a student and member of the US Army Junior Reserve Officers' Training Corps programme.
Video shows him wearing a maroon or burgundy coloured top as he was put in the back of a cruiser by half a dozen officers.
Students barricaded themselves into their classrooms, while others were seen running out of the building with their hands in their air as police and Swat teams swarmed the school.
Those fleeing the school, in single file, each threw their backpack into a large pile and huddled together under trees across the street.
The school district said the shooting happened shortly before dismissal time when students heard what sounded like gunfire.
Desperate parents and relatives of students rushed to the scene to find out if their children were among the injured.
'It's for real'
One mother, Michelle, whose daughter was inside, said at least 20 students and teachers still barricaded in the school buildings. The unnamed mother said her daughter sent her a text that said: "There's been a shooting in school ... and it's for real."
Speaking outside the police perimeter, Michell said: "She was texting me up until about four minutes ago and now she's not responding and I'm getting nervous. Last she texted me she was in a building from across where the shooting was at. I'm on pins and needles because she isn't responding to me now."
CBS Miami reporter Rick Folbaum said he was exchanging messages with a child hiding in a closet inside the school.
"I'm continuing to text with a student, a young girl who I know well, who is in the building right now who told me that she heard a loud noise and what sounded like gunfire, three shots," he said.
"She texted: 'All of a sudden there was a really loud noise…..people are crying the closet'.
Parent Caesar Figueroa told CBS: 'My daughter is with a friend and is trapped in a closet. She is afraid to talk out loud. It's like a war zone here with cops, machine guns, helicopters. The FBI is here, everyone is here. I told my daughter not to call me because I don't want anyone to hear her voice."
Photographs taken by students inside the school showed them crouching behind piles of chairs and hiding behind desks.
The shooter reportedly fled when police arrived, mixing with other students leaving the school.
Video showed at least five people being treated by paramedics at the scene while students were led away from the school in a line. But reports show that many more were shot and injured.
Coral Springs police have advised people to avoid the neighbourhood.
President Donald Trump has tweeted about the shooting to offer his condolences to the victims.
'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,' he wrote.
He added that he'd spoken with Florida Governor Rick Scott and "we are working closely with law enforcement on the terrible Florida school shooting".
White House deputy press secretary Lindsay Walters said: "The president has been made aware of the school shooting in Florida. We are monitoring the situation. Our thoughts and prayers are with those affected."
Police asked parents to tell children still inside to "remain calm and barricaded until police come to their room".
The shooting comes just a few weeks after a 15-year-old boy opened fire at his rural Kentucky high school, killing two and injuring more than two dozen others.