The children at the daycare centre in Uthai Sawan were mostly stabbed to death, police said.
The children at the daycare centre in Uthai Sawan, a town 500 km (310 miles) northeast of Bangkok, were mostly stabbed to death, they said.
Police identified the attacker as Panya Khamrap (34), a former member of the force who was dismissed from his post last year over drug allegations and he was facing trial on a drugs charge.
Khamrap had been in court earlier in the day and had then gone to the daycare centre to collect his child, police spokesperson Paisal Luesomboon told broadcaster ThaiPBS.
When he did not find his child there, he began the killing spree, Paisal said. "He started shooting, slashing, killing children at the Utai Sawan daycare centre," Paisal said.
Videos posted on social media showed sheets covering what appeared to be the bodies of children lying in pools of blood in the garden of the daycare centre.
Reuters could not immediately authenticate the footage.
About 30 children were at the facility when the attacker 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.
"The shooter came in around lunch time and shot four or five officials at the childcare centre first," Jidapa told Reuters.
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 attacker forced his way into a locked room where the children were sleeping, Jidapa said. She said she thought he killed children there with a knife, adding that a teacher who was eight months pregnant was also stabbed to death.
Prime Minister Prayuth Chan-Ocha, in a statement on Facebook, called the shooting a "shocking incident".
"I have ordered the police chief to travel to the scene immediately to take necessary actions and all involved parties to provide immediate relief to all affected people," he said in the statement.
Deputy Prime Minister Prawit Wongsuwan will travel to Uthai Sawan to visit the scene on Thursday, his office said.
By afternoon, officials stood guarding the front entrance to the daycare centre, a pink, one-storey building surrounded by a lawn and small palm trees.
In a gazebo nearby, anxious-looking people gathered, waiting mostly in silence for news. One woman could be heard weeping.
"He (attacker) was already stressed and when he couldn't find his child he got more stressed and started shooting," police spokesperson Paisal told broadcaster ThaiPBS, adding that the man 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 Southeast Asia. Illegal weapons, many brought in from strife-torn neighbouring countries, are common.
Police said, however, that the gun used in the shooting had been obtained legally.
Mass shootings in Thailand remain rare, althoughin 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.