The incident at Banksia Road Public School also left three girls in hospital with injuries.
Twenty-four children were inside the demountable classroom at the time, Australian police said.
The driver of the car, a 52-year-old woman, is being questioned by police. Authorities say they do not believe the crash was intentional.
The incident happened about 09:45 local time on Tuesday (22:45 GMT Monday) in the suburb of Greenacre.
Paramedics described the scene as “pandemonium”.
“Obviously it was a scene of carnage,” said Supt Stephanie Radnidge, from New South Wales Ambulance.
“There were a number of distressed and overwhelmed children and teachers at the scene of a horrible accident.”
The two boys were taken to a nearby hospital, where they died from their injuries. A girl, nine, remains in a serious condition, while the two others, both eight, were stable, authorities said.
Police said “a number” of other children received minor injuries and were treated at the scene. (Courtesy BBC)