Two Beacon High School students were hospitalized with burns after an incident in a chemistry lab went haywire and set the students aflame on Thursday, officials said.

Both unidentified students, a male and a female, were taken to Weill Cornell Medical Center after a demonstration from a chemistry teacher sent a fireball shooting across a counter in the lab around 9 a.m. Thursday, according to published reports.

A quick-thinking student grabbed a fire extinguisher and gave it to the teacher, identified in published reports as Anna Poole, who put out the flames, reports said, but not before the boy suffered severe burns all over his body, putting him in serious condition, the FDNY said. The female's burns were less severe, according to officials. No other injuries were reported, the FDNY said, and the exact cause of the incident is under investigation.

Beacon, on the Upper West Side, is among the city's best public schools, counting among its alumni Mayor Bill de Blasio's daughter, Chiara.