The attack occurred at Ban Yalaeboh School in Rueso district about 8am, where eight police were guarding the students and teachers.
Pol Lt Manachai Jai-uea, who headed the security team at the school, said the gunmen hid in a rubber plantation behind the school and fired M16 assault rifles at police in the compound.
Some police rushed teachers and students inside for safety while others shot back at the attackers. The gunmen then retreated. About 20 spent assault rifle cartridges were found in the plantation.
The school's director, Wannapha Phromphet, cancelled classes for the rest of the week because teachers and students were in shock. It will reopen on Monday.