Officials said the gunman began shooting outside the Marjory Stoneman Douglas High School in Parkland, Florida at about 2:40pm local time (19:40 GMT) on Wednesday. Some students believed a fire drill was taking place.

The gunman, armed with a semiautomatic AR-15 rifle, a gas mask, smoke grenades and "multiple magazines" of ammunition entered the school and continued his rampage.

Those inside the school can be heard yelling "Oh my God!" as shots rang out in videos circulating on social media.

A student told local media he had to wait in a closet while the school was under a "code red" lockdown.

"I was just in disbelief. I was texting my friends and my family," the student told WPTV-TV, an NBC affiliate in West Palm Beach, Florida, after being evacuated from the school.

"I didn't believe it was actually happening," he said.

The gunman then fled the scene and was taken into custody about an hour later in a neighbouring city, officials said.

"It is a horrific situation," Broward County public school Superintendent Robert Runcie told The Associated Press. "It is a horrible day for us," he added.

Sheriff Scott Israel called the shooting "catastrophic", saying that "there really are no words".

"My prayers and condolences to the families of the victims of the terrible Florida shooting," US President Donald Trump said on Twitter. "No child, teacher or anyone else should ever feel unsafe in an American school," he added.

18 school shootings in 2018

Everytown for Gun Safety Support Fund, an organisation advocating for gun control, had recorded 17 shootings at schools this year alone prior to Wednesday's incident in Florida. Two were classified as attempted or completed suicides with no intent to harm others. At least one occurred when a gun unintentionally discharged.

In January, a 15-year-old male student allegedly opened fire at a high school in Benton, Kentucky, killing one person and injuring more than a dozen others.

Nearly 300 school shootings have been reported since 2013 across the United States, Everytown said.

Wednesday's shooting is among the top 10 deadliest mass shootings in the US modern history.

It has again renewed the debate surrounding gun control in the US.

Last year, a gunman opened fire on a church in Texas, killing 26 people. About a month earlier, another gunman killed at least 58 people at a concert in Las Vegas, Nevada.