The shooter entered Silver Rail Elementary School in the town of Bend, Oregon by firing through locked doors, police said, only providing the boy's age.
The dead were children aged five, eight and 11, and one teacher.
Another child, aged seven, and a 54-year-old teacher were injured and taken to hospital with critical injuries, Bend Police Chief Mike Krantz told a press conference.
Police first received a call after midday from a person in a vehicle outside the school who reported being shot at multiple times by someone with a long gun, Krantz said.
Dozens of further emergency calls came saying the shooter had entered the school and it was immediately directed to go into lockdown.
Some of the calls came from inside the school.
Krantz said the community member, whom he did not identify, saw the suspect go inside and pursued him.
Police arrived on scene and confirmed moments later the suspect was dead, he said.
Oregon Governor Tina Kotek, at the same media conference, thanked the community member who "heroically intervened to stop further loss of life".
"No parent should have to have this kind of day and no community should have to live through this kind of day," she said.
"And as we learn more about the children and the adults who have been killed or injured, and their families and their loved ones, we are going to do a lot of crying.
"And we are going to cry together and we're probably going to cry privately."
Krantz said every police officer in Bend, a city of about 100,000 residents in rural central Oregon, went through a full day of active shooter training in August.
"Unfortunately, this is something we train for on a regular basis and we must," he said.
"This is going to be a long investigation."
The school serves kindergarten through to fifth grade, roughly ages five to 11, and has about 450 students and 40 staff members, officials said.
Gun control advocate Gabrielle Giffords, a former congresswoman who survived a mass shooting in 2011, said in a statement she was "heartbroken" by the shooting in Bend.
"This cannot continue to be a reality in our country. Leaders at every level must step up and act," she said.
School shootings have become a recurring feature of American life.
High-profile attacks include those at Columbine High School in 1999, Sandy Hook Elementary School in 2012, Marjory Stoneman Douglas High School in 2018 and Robb Elementary School in Uvalde, Texas, in 2022.
Each shooting revives debates over gun laws in a country where gun rights are protected under the Constitution's second amendment.
Gun rights advocates have argued for arming teachers as a means of defence.
with AP an DPA