A teenager was killed and eight students injured after two students opened fire at a school in Denver, Colorado.

Douglas County Sheriff Tony Spurlock said the pair walked into the STEM School Highlands Ranch and began shooting students in two classrooms.

Within minutes, deputies at a nearby sheriff’s department substation entered the school and arrested the two suspects after a struggle.

School Shooting Colorado
Vehicles block the road to the STEM Highlands Ranch school(David Zalubowski/AP)

“As officers were arriving at the school, they could still hear gunshots,” Douglas County Undersheriff Holly Nicholson-Kluth said.

Authorities have identified one of the suspects as 18-year-old Devon Erickson.

Mr Spurlock said the second suspect is a juvenile and that both attended the school and neither were previously known to authorities.

“I have to believe that the quick response of the officers that got inside that school helped save lives,” he said.

The shooting comes nearly three weeks after neighbouring Littleton marked the grim 20th anniversary of the Columbine school massacre that killed 13 people.

The two schools are separated by about seven miles in adjacent communities south of Denver.

School Shooting Colorado
A law officer protects a busload of students at a recreation centre (David Zalubowski/AP

“Tragically, this community and those surrounding it know all too well these hateful and horrible acts of violence,” White House spokesman Judd Deere said in a statement.

US president Donald Trump had been briefed on the shooting and was in touch with state and local officials, he said.

As the gunfire rang out, students ran through the halls shouting “School shooter!”

Some wondered at first if it was a joke or a drill.

“At the moment no one really knew what was going on so I didn’t know they were bullets,” said pupil Sophia Marks.

“I just kind of saw like flashes and we heard bangs.”

Chris Elledge, 15, said his teacher told the class to hide behind weight equipment in the room, where they stayed until police arrived.

“They busted in the room, and they were asking if there was any suspects in the room, if we were OK, and they escorted us out to go out to the front of the building,” he said.

Three hospitals reported treating eight people in connection with the attack, including two who were listed in serious condition.

Democratic Representative Jason Crow, a gun-control supporter whose congressional district includes STEM, said the gun violence cannot continue.

“It is not enough to send thoughts and prayers. It is empty. It is weak, and it does an injustice to our children who are on the front lines of this violence,” he said.