Police successfully persuaded a gunman to surrender after he released hostages, including his ex-wife, at a school in Maha Sarakham on Thursday.
The 36-year-old man, identified only as Akarawat, entered Khaothung School around noon, police said.
Witnesses reported that the man had a conversation with his former wife, who is a teacher, in the school. The meeting happened about two months after their breakup. Their four-year-old child was also at the scene.
An argument started, leading the man to leave the teacher's room and fire a gunshot into the air.
Other teachers told about 140 students to take cover, and only the woman teacher and her child were left in her room.
About an hour later, police managed to convince the gunman to release all children and teachers, including his ex-wife and child.
However, despite hours of negotiation by police and his relatives, the man remained on the second floor of the school, firing his gun and refusing to surrender.
After about five hours of negotiation, police arrested the man at about 4.45pm.
Khaothung is a school for kindergarteners, pupils and junior secondary school students.