The boy shot his grandparents dead at dawn on Friday in their two-storey house bordering rice fields in Bang Bua Thong on the outskirts of Bangkok.
Each was killed by a single gunshot to the head, a Thai police official said.
By noon, bodies lay strewn at the 14-year-old's school - five more dead and 23 wounded - before he turned the gun on himself, ending Thailand's worst mass shooting since 2022.
Police Colonel Thadsakorn Konthong, superintendent of Bang Bua Thong Police Station, said the boy killed his elderly relatives at around 5am local time with a firearm and bullets belonging to his grandfather.
"An initial inspection found signs that the firearm had been searched for inside the grandfather's bedroom," Thadsakorn told Reuters.
The whereabouts of the boy's parents remain unclear.
After shooting his grandparents, the teenager boarded the school van for the 45 minute journey to Debsirin Nonthaburi School, carrying the gun and bullets, said Thadsakorn.
About half an hour into the boy's second class of the day he drew out the gun and began shooting again, police estimate.
Police were called to the scene where students were evacuating the building or taking cover under their desks.
The teenager is believed to have first shot teachers on the sixth floor of the building where he studied, killing three of them, said Police Major General Dejrapee Kongdee, commander of the Nonthaburi Provincial Police.
One was a female Thai language teacher who he shot in the eye, according to a timeline of the incident shared by Thai police. The gunman then appears to have continued down a corridor, shooting at students.
"He then walked down the stairs and encountered the school's deputy director and the director's secretary, who were going up the stairs to check on the situation," Dejrapee told Reuters.
"The attacker shot and killed both of them on the staircase."
The boy began walking towards another building but appeared to change his route after seeing police arrive, and he fled into a four-storey structure, Dejrapee said.
Emergency workers described chaos at the scene with multiple students being treated for wounds to the back, chest and arms.
Police eventually found the teenager on the fourth floor, where he had already shot himself, said Dejrapee.
"He was still alive, so they performed CPR and rushed him to the hospital," he said.The 14-year-old died soon after.
In all, he had used at least 26 bullets. Another 34 rounds were found in his possession.
The boy's motives remain unclear, though Thai Prime Minister Anutin Charnvirakul told reporters he was stressed from his studies.
Friday's rampage has renewed scrutiny of gun regulations in Thailand, Southeast Asia's largest gun-owning nation with roughly 15 firearms per 100 residents.
Anutin, who tightened gun laws when he was interior minister following a previous mass shooting, said he will propose a new law to restrict the carrying of firearms by the public.