Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

BANGKOK — A soldier suspected of killing at least 29 people during a shooting rampage in northeastern Thailand was shot and killed Sunday, Thai officials said.

The alleged gunman, Sgt. Jakrapanth Thomma, shot and killed a soldier and a woman at a military barracks in the city of Nakhon Ratchasima before turning his attention to a nearby mall, said police spokesman Kissana Phathanacharoen.

After visiting victims in hospitals in the city, Thai prime minister Prayuth Chan-Ocha told reporters that the "a personal conflict over a house deal," had sparked the shooting, according to Reuters press.

"He had an issue with money and fought for three days. Nobody expected it to turn violent," he said.

He added: "I hope this is the only one and the last incident, and that it never happens again. No one wants this to happen. It could be because of this person's mental health in this particular moment."

Thomma escaped in a military Humvee and opened fire at a number of different locations throughout the city, police said. He then holed up in a shopping mall for more than 10 hours after the attack began, police in Thailand told NBC News.

Lt. Gen Piya Uthayo, Thailand's assistant national police chief, said that out of the 29 victims identified so far, 23 were civilians, three were army officers and another three were police officers.

Let our news meet your inbox. The news and stories that matters, delivered weekday mornings. This site is protected by recaptcha

He added that 27 people who were injured in the rampage remain in hospitals.

As the standoff moved into early Sunday morning local time, bursts of automatic gunfire were heard from inside the shopping mall when Thai security forces suddenly rushed in to free hundreds of people who had been trapped inside.

Download the NBC News app for breaking news

Thai security forces take cover behind an ambulance as they chase a shooter hidden in a shopping mall after a mass shooting in front of the Terminal 21, in Nakhon Ratchasima, Thailand on Feb. 9, 2020. Athit Perawongmetha / Reuters

"We don't know why he did this. It appears he went mad," said defense ministry spokesman Lt. Gen Kongcheep Tantrawanit.

Video taken outside the mall and shared on social media showed people taking cover in a parking lot as gunshots were fired. Authorities continued to try to arrest the gunman and rescue shoppers inside as the time pushed into Sunday morning in Thailand.

From within the mall, Thomma taunted police and the internet as he intermittently posted photos of himself holding various weapons or shared memes with threatening messages on his Facebook page. His account was eventually removed by the social media company.

"There is no place on Facebook for people who commit this kind of atrocity, nor do we allow people to praise or support this attack," a Facebook spokesperson said in a statement.

People who were able to get out of a mall are escorted outside by armed commando soldiers in Nakhon Ratchasima, Thailand, on Sunday. Sakchai Lalit / AP

Thailand's minister of public health said his agency had brought together more than 100 doctors and nurses to help the injured. He said they have 1,700 units of blood.

“I’ve made sure that all medical staff and units are trying their best to help those injured. I urge the public to not share photos of the incident and refrain from commenting,” Minister of Health Anutin Charnvirakul said in a statement.

The U.S. State Department put out a warning of an active shooter at a shopping mall in Nakhon Ratchasima, and advising to avoid the area.

The incident comes just a month after another high-profile mall shooting, in the central Thai city of Lopburi. In that case, a masked gunman carrying a handgun with a silencer killed three people, including a 2-year-old boy, and wounded four others as he robbed a jewelry store.

A suspect, a school director, was arrested less than two weeks later and reportedly confessed, saying he did not mean to shoot anyone.

Nat Sumon reported from Bangkok and Isobel van Hagen reported from London.