It is common to hear the accusation that religion was created by those who feared death and needed some sort of afterlife. Really? And what research is that based on? Your neighbour who had a medical scare and decided to start attending church? I am sure that there are people who get interested in religion because of a fear of death but historically that is not a very good explanation. I will provide a couple of examples.
Ancient Egyptian religion would seem to support the afterlife hypothesis, with all its mummies and pyramids and magnificent tombs. Except when you look closely and discover that the afterlife was originally only for the Pharaoh, then gradually for the aristocracy and only later for people in general. Ancient Greek religion had a concept of Hades where the shades of the dead dwelt. But this was no source of hope for the Greeks. It was a shadowy existence that was not much fun. Even the great heroes lacked hope for a glorious afterlife.
What about the Bible? We all know Christianity is all about the afterlife. It is true that the resurrection, both of Jesus and the believer, is very important to the Christian faith. But before there was an New Testament, there was an Old Testament. Read through the Old Testament and look for evidence of an afterlife. Most of post-death existence is described as Sheol, which despite the KJV translation as hell, is really just the grave. If there is any consciousness in Sheol, it is that shadowy existence such as what we find in the Greek Hades. There are only two passages in the Old Testament that clearly provide hope for an afterlife, and both are fairly late.
“Your dead shall live; their bodies shall rise. You who dwell in the dust, awake and sing for joy! For your dew is a dew of light, and the earth will give birth to the dead.” (Isaiah 26:19 ESV)
“And many of those who sleep in the dust of the earth shall awake, some to everlasting life, and some to shame and everlasting contempt. And those who are wise shall shine like the brightness of the sky above; and those who turn many to righteousness, like the stars forever and ever.” (Daniel 12:2–3 ESV)
If you want to learn more about the development of the afterlife in the Old and New Testaments, see my book Finding a New Land. The point is that an afterlife does not play a central role in the Old Testament and therefore was not the motivation for biblical religion. I am not suggesting that the afterlife is unimportant, only that a fear of death is not sufficient to explain the rise of religion, either in general or in the Bible.