A 16-year-old gunman shot dead three children and a teacher at a primary school in Bend, Oregon, on Thursday afternoon before a member of the public followed him into the building and shot him dead, police said.

The attacker forced his way into Silver Rail Elementary School by firing at locked doors, Bend Police Chief Mike Krantz said. The children killed were aged five, eight and 11. A seven-year-old pupil and a 54-year-old teacher were taken to hospital in a critical condition.

Police said a bystander saw the attack begin, pursued the teenager into the school and engaged him. Officers reached the scene about three minutes later and found the attacker dead. It is not yet clear whether he had any link to the school, and police have not named him or the victims.

Oregon Governor Tina Kotek praised the community member who "heroically intervened" to stop further loss of life. "Your actions carry a heavy emotional burden and I just want you to know that my thoughts are with you as well," she said at a briefing. Steve Cook, superintendent of the Bend-La Pine school district, said the community was "heartbroken" and "horrified".

Classes and after-school activities were cancelled across the district on Friday. Around 450 children attend Silver Rail Elementary, which has more than 40 adult staff, and a candlelit vigil was held in Bend on Thursday evening.

According to the K-12 School Shooting Database, there were 235 shooting incidents at American schools last year and at least 140 so far this year. A person under 18 cannot buy a firearm in Oregon, though juveniles may possess one with parental permission for limited uses such as hunting.