The 18-year-old student killed in a shooting at a suburban Denver school was a high school senior days away from graduating, police said, as one of his classmates recalled how the teen tried to stop one of the shooters in the attack that cost him his life and left eight others wounded.

The young man who was slain has been identified as Kendrick Ray Castillo, a robotics enthusiast, the Douglas County sheriff’s office said on Twitter.

Sheriff Tony Spurlock told a morning news conference the reason for the attack at the Science, Technology, Engineering and Math (STEM) School in Highlands Ranch remained unclear. Two suspects, both students, were taken into custody — Devon Erickson, 18, and a juvenile.

Student Nui Giasolli told NBC’s Today show that she was in her British literature class when one of the shooters entered and pulled out a gun.

Giasolli said Castillo lunged at the gunman, who then shot the teen. Giasolli says Castillo’s actions gave the rest of the class time to get underneath their desks and then run across the room to escape to safety.

John Castillo, the teen’s father, said his son was a hero and he wants people to know about him. 

Another student hailed as a hero is 17-year-old Brendan Bialy, who has been preparing to join the Marines.

The Marines said on Wednesday that Bialy put his own safety at risk and showed “courage and commitment” in helping to tackle one of the shooters.

Marine Capt. Michael Maggiti said the teen was not injured.

Michael Schwart, a former student of the school told CBS he spoke to friends from the STEM school who told him “a “couple” of students were “able to pin [the shooter] to the ground.”

Suspect identifies as female

Denver’s ABC television affiliate, citing an unidentified police source, reported on Tuesday that one of the suspects wanted to transition to male from female and had been bullied for it.

Spurlock said one of the suspected shooters previously identified as male, but was a female under the age of 18. 

Spurlock declined to answer a reporter’s question about whether the younger suspect was transgender. That suspect has not been publicly identified and is being charged separately as a juvenile, authorities said.

“Right now we are identifying the individual as a female, because that’s where we’re at,” he said. “We originally thought the juvenile was a male by appearance.”

Parents pick up their children after a shooting at the STEM School in Highlands Ranch, Colo., on Tuesday. (Chet Strange/AFP/Getty Images)

Spurlock said the suspect had been identified as male “before the detectives were able to get the medical — and detectives were able to speak to her.”

KMGH-TV reported late Tuesday that the juvenile suspect is a transgender male in the process of transitioning from female to male. The television station cited anonymous sources close to the investigation.

The two suspects opened fire in two separate classrooms and were arrested within minutes at the public charter school about 40 kilometres south of Denver, Spurlock said.

Police officers stand watch at the scene of the shooting in which one student was killed and eight wounded. (Tom Cooper/Getty Images)

“A student’s life was taken too soon by this act of violence,” Colorado Gov. Jared Polis said at a news conference. “I share the heartbreak, the frustration, the sickness.”

Some of the worst mass shootings in the United States have occurred in Colorado.

The attack occurred less than a month after the 20th anniversary of the Columbine High School massacre in nearby Littleton, about eight kilometres from the Highlands Ranch school. In 2012 a man opened fire at a movie theater in Aurora, another Denver suburb, killing 12 people and wounding scores more. 

Last month a Florida teen who, according to authorities, was obsessed with the Columbine shooting and who may have been planning her own attack, was found dead of an apparent suicide in the mountains outside Denver. 

Further, the attack at the STEM school came a week after a gunman opened fire on the Charlotte campus of the University of North Carolina, killing two people and wounding four others.

But what happened inside STEM remains unclear.

A man who identified himself as Fernando Montoya said his 17-year-old son, a junior at STEM, was shot three times when a shooter walked into his classroom and opened fire.

“He said a guy pulled a pistol out of a guitar case and started to shoot,” Montoya told a Denver TV station.

The bloodshed shocked the affluent suburb of Highlands Ranch. Parents and students had considered the school a safe place for its 1,850 pupils ranging from kindergarten to Grade 12.