A soldier who went on a shooting rampage in northeastern Thailand, killing at least 29 people, has been shot dead by security services after he holed himself up in a shopping centre.

Police and military sources told Reuters they had killed 32-year-old Jakrapanth Thomma on Sunday morning, a few hours after a failed raid on the Terminal 21 complex in Nakhon Ratchasima left one member of the security forces dead and two injured.

More:

"The police have killed the perpetrator and rescued eight hostages. Some were wounded," said a member of the security sources who declined to be named because they were not authorised to speak to the media.

The death was confirmed by Public Health Minister Anutin Charnvirakul.

"Thank you police and army for ending the situation. Shooter shot dead!!!" Anutin said in a post on Facebook.

The province's governor, Wichien Chantaranochai, on Sunday night said a total of 29 people had been killed and 57 were wounded.

"It is unprecedented in Thailand, and I want this to be the last time this crisis happens," Prime Minister Prayuth Chan-ocha said earlier on Sunday after visiting the wounded in hospital.

The mass shooting began around 3pm (08:00 GMT) on Saturday when Jakrapanth opened fire in a house before moving to an army camp and then to the mall, posting messages on Facebook as he went.

Police closed off streets around the mall and kept journalists behind a security cordon, fearing the gunman had taken hostages.

Dozens of terrified shoppers were evacuated from the centre as armed police said they had "taken control" of the ground floor of the complex.

Al Jazeera's Thailand producer Kittiphum Sringammuang said police were working to establish the motive for the mass shooting.

"The motive for the attack is still unclear," Kittiphum said. "The police will start collecting evidence at the crime scene and will begin investigations especially on what was the motive behind the attack. It seems like he had an issue with his commanding officer, but there's no indication of why he attacked civilians in broad daylight."

The gunman wrote on his Facebook page earlier in the day that "Death is inevitable for everyone". The suspect also posted a picture of what appeared to be his hand holding a gun.

At one point after the shooting began, he wrote online: "Should I give up?" before his account became inaccessible.

Thai media said the suspected shooter had worked at an army base close to Nakhon Ratchasima, which is about 250km (155 miles) from the capital Bangkok.

Before the attack, Jakrapanth had posted on his Facebook account that he was out for vengeance - but he did not say for what.

The prime minister said the killings may have arisen from a grudge over a land deal in which Jakrapanth felt he had been cheated.

Dozens of terrified shoppers were evacuated from the shopping centre where Jakrapanth sheltered [Athit Perawongmetha/Reuters]

"We don't know why he did this. It appears he went mad," said Ministry of Defence spokesman Kongcheep Tantrawanit.

The prime minister expressed condolences to the families of those killed, a government spokeswoman said.

Amateur footage

Local media earlier showed footage of the soldier getting out of a car in front of the shopping centre and firing a series of shots.

Footage circulating online showed panicked scenes, with people fleeing and what appeared to be the sound of automatic gunfire filling the air.

200121083056482

A woman interviewed by Thailand's Channel One television said she had heard gunshots when she was at the shopping centre and hid in a clothing store with other people before escaping.

Thailand has a high rate of gun ownership but mass shootings by soldiers targeting civilians are rare.

Several shootings at courthouses late last year also renewed concern about gun violence in the country.

In one high-profile case, two lawyers were shot dead by a clerk at a court in eastern Thailand during a hearing over a land dispute.