Hungary edged Poland 2-1 to become the second team behind Kazakhstan to earn promotion to the 2016 IIHF Ice Hockey World Championship in Russia.