A mass shooter in Thailand killed a total of 20 people and wounded 42 before he himself was shot dead by security forces on Sunday, a health official said.