A soldier who killed 21 people in a gun rampage in the Thai city of Nakhon Ratchasima has been shot dead by the security forces, Thai police say.
Jakraphanth Thomma killed his commanding officer on Saturday before stealing weapons from a military camp.
The suspect continued his attack in a shopping centre in Nakhon Ratchasima, also known as Korat,
He posted material to social media, but his motives for his actions remain unclear.
What happened at the shopping centre?
Shortly after 03:00 local time gunfire was heard as the security forces raided the building, trying to dislodge the gunman.
One member of the security forces was killed and two injured.
Several people were led out of the centre, but there were concerns that more people were being held hostage.
At 09:30 local time on Sunday, police confirmed the gunman had been shot dead, but so far there are no more details about how the operation concluded.
Earlier reports said the gunman, aged 32, had tried to escape via the back of the building.
The suspect's mother was also brought to the shopping centre to try to persuade him to give himself up.
One of the people freed told the BBC how she and others hid in a bathroom on the fourth floor, before fleeing to the second and hiding under a restaurant table for three hours, hearing at least four gunshots before she saw some soldiers and could get to safety.
Public Health Minister Anutin Charnvirakul earlier said that 16 people had died at the scene of the shootings, with another four dying later in hospital.
A total of 31 people have been injured, with 10 of them in a critical condition. But there are fears the numbers could rise.
How did the attack unfold?
It began at about 15:30 local time on Saturday at the Suatham Phithak military camp, where the commanding officer, named by the Bangkok Post as Col Anantharot Krasae, was killed.
The Post said a 63-year-old woman, Col Anantharot's mother-in-law, and another soldier were also killed there.
The suspect seized arms and ammunition from the camp before taking a Humvee-type vehicle.
He then opened fire at a number of sites before arriving at Terminal 21 at about 18:00 local time.
Local media footage appeared to show the suspect getting out of his vehicle and firing shots as people fled.
CCTV footage showed him inside the shopping centre with a raised rifle.
What did the suspect post on social media?
He posted on his social media accounts during the attack, with one post on Facebook asking whether he should surrender.
He had earlier posted an image of a pistol with three sets of bullets, along with the words "it is time to get excited" and "nobody can avoid death".
Facebook has now taken the page down.
It said: "Our hearts go out to the victims, their families and the community affected by this tragedy in Thailand. 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."
-BBC