Gods of war came first. Yahweh, for example, was a regional god that was considered a "divine warrior" and was prayed to for favor long before the idea of an afterlife or heaven or hell came into play -- people that died just went to sleep in Sheol. Then the Persian conquest introduced Zoroastrianism, and with it the idea that the bad people will burn while the good people will be rewarded, which syncretized with and was adopted by Judaism.
I think the gods of the afterlife were somewhat of a "cosmopolitan" development as societies gained elements of stability -- i.e. when you're hungry you pray for food so you don't die, when you're cold you pray for warm weather so you don't die, when there's war you pray for victory so you don't die, but when these needs are taken care of you pray that when you get old and die you don't really die.
So likewise, when other cultures were developing savior gods (Osiris in Egypt, Dionysus, Adonis, and Zagreus in the Greek world, Tammuz in Sumeria, Attis in Phrygia, Mithra in Persia), a sect of Judaism developed there own with Jesus.