Nakhon Ratchasima (Thailand): At least 26 were killed, including a 13-year-old boy, before a Thai soldier was gunned down in a malll that saw an "unprecedented" shooting spree. Offering the first speculation behind the motive, Thailand's prime minister Prayut Chan-O-Cha said on Sunday that he went on the rampage due to a debt dispute.

The attacker, a junior army officer identified as Sergeant-Major Jakrapanth Thomma, used a stolen M60 machine gun, rifles and ammunition from one of Thailand's largest barracks as well as a military humvee to carry out the attack.

The 17-hour-ordeal saw heavy exchanges of gunfire before the gunman was killed in Nakhon Ratchasima which is also known as Korat on Sunday morning.

Twenty-six people including civilians -- the youngest a 13-year-old boy -- and security forces were killed by the rogue soldier, the kingdom's premier said.

"It is unprecedented in Thailand, and I want this to be the last time this crisis happens," he said outside a hospital where victims, including at least two undergoing brain surgery, were being treated.

Prayut, a gruff former army chief, blamed a "personal problem" over the sale of the house for the soldier's rampage, which began on Saturday afternoon near an army barracks and was for several hours relayed by the gunman via Facebook posts.

Shocked evacuees recounted how an ordinary Saturday at the busy shopping centre descended into horror as the gunman entered, sparking an hours long ordeal.

"It was like a dream... I'm grateful I survived," Sottiyanee Unchalee, 48, told AFP, explaining she hid in the toilet of a gym inside the mall as she heard the gunfire.

The bloodshed began Saturday afternoon when he shot three people -- among them at least one soldier -- at a senior officer's house and then at the nearby army barracks, before driving a military vehicle to the town centre.

Throughout the day, he posted images of himself and wrote several posts on his Facebook page as the attack unfolded. His facebook account was later removed.

The city is home to one of the largest barracks in Thailand, a country where the military is enmeshed in politics and society. The nation also has one of the highest rates of gun ownership in the world, and several shootings at courthouses last year renewed concern about gun violence.

Also Read | 4 Dead, 3 Injured In Brooklyn Club Shooting