In short, they lived to hike another day. Since we all inherited this propensity to err on the high side of perception from our successful ancestors, we all possess some natural propensity toward religious belief. Because humans are highly organized, they are capable of generating a wide array of phenomena. Thus, much is explicable by appeal to humans or something modeled on them. As theoretical entities, gods are reducers of complexity and diversity because the entities on which they are modeled, real humans, are generators of complexity and diversity.
Gods appear as powerful components of theory because they are modeled on powerful real organisms.
The fact that most of the world's processes and features arise out of vast impersonal forces of self-organizing power instead of acts of intentionality does not occur to us naturally. It has taken centuries of careful experimentation and hard theoretical work to learn the truth. But when we do submit our hypotheses to the stern discipline of modern natural science, we feel alienated from our normal thought processes. Our impulses betray us. Removing anthropomorphism from human thought is very likely impossible, at least for the foreseeable future.