Thai security forces on Sunday killed a soldier after he carried out a shooting rampage that left at least 21 people dead, police and military sources said.