A member of the security forces was killed early on Sunday in a raid on a shopping mall in northeastern Thailand where a soldier who shot dead at least 20 people was holed up.
The killings began at around 3 pm (08:00 GMT) when the soldier opened fire in a house before moving to an army camp and then to the mall in Nakhon Ratchasima, posting messages on Facebook as he went.
Early on Sunday, gunfire broke out at the mall as security forces tried to dislodge the soldier, identified by police as 32-year-old Jakrapanth Thomma, who is armed with assault weapons stolen from his barracks.
Public Health Minister Anutin Charnvirakul told reporters at the scene that one member of the security forces had been killed and two wounded in the raid. As he spoke, a series of explosions and further shooting echoed from the Terminal 21 mall.
Police closed off streets around the mall and kept journalists behind a security cordon.
Dozens of terrified shoppers were evacuated from the centre as armed police said they had “taken control” of the ground floor of the complex.
At least 31 people have been wounded.
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 had begun, 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 250 km (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 attacker remained in a shopping centre and had not yet been apprehended, the police said.
“We don’t know why he did this. It appears he went mad,” said Ministry of Defence spokesman Kongcheep Tantrawanit.
Al Jazeera’s Wayne Hay, reporting from Bangkok, said that the situation around the shopping centre was still evolving.
“Police say that the suspect has hostages inside the shopping centre with him, but it is not clear how many,” he said.
Hay added that gunshots were heard from the building late at night and in the early hours of Sunday.
Prime Minister Prayuth Chan-ocha expressed condolences to the families of those killed, a government spokeswoman said.
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.
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 one of the highest rates of gun ownership in the world 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.