Bangkok: An armed soldier who went on a shooting rampage in Nakhon Ratchasima city in the country’s northeast, killing at least 20 people, was shot dead by security services on Sunday morning after he holed himself up in a shopping centre.

Following an hours-long standoff, the police and military sources confirmed that they had killed 32-year-old Jakrapanth Thomma, The Washington Post reported.

The alleged shooter, who carried an assault rifle, was a sergeant in the Thai military. He was clad in camouflage and a helmet during the rampage.

The attack is at least the second mall shooting in Thailand this year.

Earlier in January, a masked gunman fatally shot three people while robbing a jewellery store in the city of Lopburi. According to media reports, the suspect was arrested, and reportedly confessed that he had not meant to shoot anyone.

Saturday’s violence began around 3:30 p.m. (local time) when police say the gunman fatally shot his commanding officer, took several military firearms and drove about nine miles in a stolen Humvee to the Terminal 21 mall in Korat, where he fired at shoppers and drivers on the packed roadways. The city is located at a distance of about three hours from Bangkok.

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 others were reported injured in the incident.

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.

Also before the attack, Jakrapanth posted online that he was out for vengeance – but he did not mention for what.

Prime Minister Prayuth Chan-o-cha has expressed condolences to the families of those killed, a government spokeswoman said.