A former policeman killed 34 people, including 22 children, in a gun rampage at a daycare centre in eastern Thailand on Thursday, later shooting dead his wife and child at their home before turning his weapon on himself.
Police identified the attacker as a former member of the force who was dismissed from his post last year over drug allegations.
He was facing trial on a drugs charge and had been in court in the hours before the shooting, police said.
District police official Chakkraphat Wichitvaidya cited witnesses as saying the gunman was also seen wielding a knife in the attack in the town of Uthai Sawan, 500 km northeast of Bangkok in the province of Nong Bua Lamphu.
About 30 children were at the centre when the gunman arrived, fewer than usual, as heavy rain had kept many people away, district official Jidapa Boonsom, who was working in a nearby office at the time, told Reuters.
"The shooter came in around lunch time and shot four or five officials at the childcare centre first," said Jidapa, adding that among them was a teacher who was eight months pregnant.
"At first, people thought the shots were fireworks," she said.
"It's really shocking. We were very scared and running to hide once we knew it was shooting. So many children got killed, I've never seen anything like it."
The gunman forced his way into a locked room where children were sleeping, Jidapa said. She said she thought he killed children there with a knife.
Police spokesperson Paisan Luesomboon told broadcaster ThaiPBS the gunman had been at a court hearing in connection with a drug case earlier on Thursday and had gone to the daycare centre to find his child, but the child was not there.
"He was already stressed and when he couldn't find his child he was more stressed and started shooting," Paisan said, adding that he had then driven home and killed his wife and child there before taking his own life.
Gun laws are strict in Thailand, where possession of an illegal firearm carries a prison sentence of up to 10 years, but ownership is high compared with some other countries in the region.
Illegal weapons, many brought in from strife-torn neighbouring countries, are common.
However, mass shootings are rare. In 2020, a soldier angry over a property deal gone sour killed at least 29 people and wounded 57 in a rampage that spanned four locations.