The attacker was named as Charles Carl Roberts, a local 32-year-old truck driver who was not Amish. Police found the bodies of three girls and Roberts when they entered the building on Monday.
Two other girls later died in hospital and seven are injured.
Police are examining suicide notes and it is thought that Roberts’ actions came in revenge for an incident 20 years ago.
Roberts had phoned his wife during the siege to say he was taking revenge for an old grudge.
Jeffrey Miller, the state police commissioner, said Roberts had entered the school in the village of West Nickel Mines and took about 30 children, as well as teachers and assistants, hostage.
Police said Roberts then ordered boys and adults out of the school before beginning to fire on the girls remaining inside.
Miller said: “It appears that when he began shooting the victims, these victims were shot execution style in the head.
“So a number of the victims that we removed out of here that did not expire on the site, were shot in the head, some were shot in the arms.”
While investigations continue into the Pennsylvania shooting, police sealed off two Las Vegas schools after they received reports of a student carrying a gun.
Last week a 16-year-old schoolgirl was killed when a man took six hostages at a Colorado school. The man opened fire before turning the gun on himself as police stormed a classroom.
On Friday, the principal of a Wisconsin high school was killed after being shot by a student.
Amish are reclusive Anabaptists. There are Amish communities in more than 20 US states.