When there is little hope we pray.
When in need and all we have are our thoughts we become religious or create religion.
It is quite possible. One theory I read a long time ago suggested this scenario:
A child dies. The father and his comrades go hunting. As they fell a stag, the child stirs, comes back to life. This prompts the men to believe that god wanted them to kill an animal for god in return for the child’s life, so they try animal sacrifice for other things too.
That’s a paraphrase from memory and might not be accurate. I forget where I read it or who wrote it. It does, however, support your idea that humans created religion due to need. In this case, the belief in a supernatural Divine Authority or god preexisted animal sacrifice. Other things I’ve read suggest humans believed in all-powerful beings to explain things like devastating storms, the rising of the sun, the growth of agricultural plants (especially cereal grains like wheat, barley, and rice), the safety of the realm and defeat of enemies. There were gods of fertility, gods of childbirth, gods of warfare, gods of the sea for sailors. For every mysterious power, for every human need, there was a god.
About two or three thousand years ago, gods began to coalesce into single all-powerful gods like the Jewish Yahweh, whom the Christians later adopted. The Romans and many others continued with the many gods but believers in Mithra had a powerful Bull or Tauras figure as a super-god. I haven’t studied Hinduism, but it occurs to me that perhaps in India people continue with the ancient traditions of a god for every need.
With the help of scientific discoveries about how the weather works, how the sun rises and sets, how plants grow, how humans are conceived and born, plus so many other things, humans have been able to evolve to rational thought. No longer do they need to pray and wait on the Lord for help. Today we can analyze our problems and figure out how to help ourselves. We may still get stuck in terrible situations or killed, but we know about this rationally and we know that if we can’t save ourselves (with the help of other people) then no god will come to our aid either. Nor will any angry god meet us “on the other side,” because we know with our rational brains that death is the end. But we can hope for some break in the situation, or meet death calmly.