Holding candles and writing condolences as monks chanted prayers, hundreds of Thais held an evening vigil Sunday for the 29 victims of an "unprecedented" mass shooting carried out by a soldier.

Sharpshooters killed the gunman on Sunday morning after a 17-hour ordeal, including a night of firefights and terrifying dashes for mall exits by shoppers trapped in the Terminal 21 mall in Nakhon Ratchasima, also known as Korat.

The provincial governor told reporters that the total death toll -- including the gunman -- stood at 30.

The dead include civilians, one of them a 13-year-old boy, and security forces going after the rogue soldier, who was upset over a debt dispute, according to Thailand's Prime Minister Prayut Chan-O-Cha.

"It is unprecedented in Thailand, and I want this to be the last time this crisis happens," he said earlier outside a hospital where victims -- some in critical condition -- were being treated.

Those who attended the somber vigil scrawled messages on white sheets of paper laid out on the ground, including "Remember Forever" and "I wish you a good afterlife".

Prayut, a former army chief, blamed a "personal problem" over the sale of a 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.

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

Prayut said the gunman overpowered security at the barracks' arsenal and that "carelessness" was not a factor.

"We don't leave the arsenal depot alone -- we had people guarding it."

Volleys of gunfire rang out as the siege ran into dawn, hours after Thai security services stormed the ground floor and freed scores of terrified shoppers.

They sent cascades of messages to friends and family on social media from storerooms, barricaded in toilets and hidden under tables as the gunman stalked the mall.

Story continues

With the machine gun slung over his shoulder and in full combat gear, Jakrapanth swaggered through the emptied out floors in haunting footage captured by CCTV cameras.

Evacuees recounted how an ordinary Saturday at the busy shopping centre descended into horror as he entered.

"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.

Filipino teacher Aldrin Baliquing said he was ushered into a storeroom by staff as the shooting began.

"We were there for six gruelling hours... I'm in shock," he said.

Scores of people made a dash for it as police and soldiers in masks and wielding assault rifles took control of the ground floor following a gun battle and scoured the fleeing crowds for the assailant.

- 'Like a Zombie movie' -

"It was total panic, it was like a Zombie movie," Chanatip Somsakul, 33, said of his escape with his wife and three-year-old daughter.

"People jumped on motorbikes and ran in all directions."

Several hours later the gunman was shot dead. Photos showed smiling units of elite soldiers and police emerging from the mall.

The gunman relayed his shooting spree through Facebook posts which charted the attack from an army barracks to the city mall.

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.

There the gunman used the stolen weapons to unleash carnage.

Throughout the day he posted images of himself and wrote several posts on his Facebook page.

In one Facebook video -- since deleted -- the assailant, wearing an army helmet, filmed from an open-top jeep, saying, "I'm tired... I can't pull my finger anymore" as he made a trigger symbol with his hand.

There were also photos of a man in a ski mask holding a pistol.

Thailand's digital economy minister Buddhipongse Punnakanta said he contacted regional executives at the social media giant to report the activity.

"I think this might be the first time that this happened in Thailand and it caused a lot of problems," he told AFP.

A Facebook spokesperson said the gunman's accounts were removed and it will "work around the clock to remove any violating content related to this attack as soon as we become aware of it."

Thailand has one of the highest rates of gun ownership in the world, and several shootings at courthouses last year renewed concern about gun violence.