Halmstad såg ut att försvara hem en oväntad seger och säkra spel i fotbollsallsvenskan nästa år.