The incident took place in the town of Shabqadar which borders the Mohmand, one of seven lawless tribal districts where Taliban militants are active.
"Some men were trying to climb the boundary wall of a private school and on seeing them, the school guard opened fire after which the men fled," district police chief Shafiullah Khan told AFP.
Nearby residents also took out their guns and fired gunshots in the air to scare the intruders away from the screaming children, he said.
Police had cordoned off the area and were searching for the suspects, he added.
Taliban militants stormed a school in Peshawar in December last year, killing more than 150 people, mostly children, in Pakistan's worst-ever terror attack.