The FBI also said it was attending the scene and assisting local law enforcement.

US television networks reported large numbers of parents had gathered outside the police perimeter.

Several witnesses inside the building at the time told news outlets that the fire alarm had been set off as the shooting began.

One student evacuated from the school told CBS that Miami students had thought it was a drill.

“We already had one earlier this morning… and then we heard gunshots; some students thought it was not that serious.”

Another 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.”

President Donald Trump tweeted condolences “to the families of the victims”. White House Deputy Press Secretary Lindsay Walters said the president had been briefed and that the White House was monitoring the situation.

Florida Governor Rick Scott said he spoke to President Trump about the shooting, and was continuing to receive updates from law enforcement.

Congressman Ted Deutch, the district’s representative, tweeted: “I’m sick about this news from home. Just spoke with the sheriff. This is devastating.”

He said it was an “incredible school in my district – great teachers and staff, involved parents and amazing kids. Spoke with the kids there just a few weeks back.”

Students were taken by bus to a “staging area” on Heron Bay Blvd, Coral Springs, where their parents could collect them.