The shooter then took his own life, officials said.
Five school staff members, including teachers and administrators, died in the shooting around 10 a.m. at Debsirin Nonthaburi School in Nonthaburi province northwest of Bangkok, Deputy Interior Minister Polapee Suwunchwee said at the scene.
The shooter also killed his two grandparents at home prior to the school shooting, Polapee said.
Prime Minister Anutin Charnvirakul, speaking after touring the school, confirmed reports that the shooter was 14 years old and killed himself. He said the boy, who lived with his grandparents, had shown signs of stress connected to school.
The gun, described by police as small and compact, was legally registered to his grandfather, he said.
About an hour after the shooting, people stood outside comforting one another as police and first responders walked around the co-educational state school, which has an enrollment of about 3,000 students ranging from 12 to 18 years old.
A witness told reporters that students hid inside a classroom while they heard gunshots from another building before police officers knocked on the door and cleared a way for them to leave the building.