"Any sufficiently advanced technology is indistinguishable from magic." That's the third of Arthur C. Clarke's laws; substitute the world "magic" for religion, and that's about the gist of Foundation. The Foundation uses religion to spread its influence and power across the galaxy. Since the people of the barbarous Four Kingdoms don't understand nuclear technology or the science behind it, they assume it comes from a supernatural source. In a sense, Asimov is playing off the idea that before people understood how lightning worked they chalked it up to Zeus. So, in Foundation, religion is something used by some to gain power over others. (Don't agree? Go to the book and prove it!)
Although the religion in Foundation helps Hardin prevent war, his inability to teach the scientific method ultimately sets society back.
Wienis's downfall resulted directly from his inability to understand religion and not Hardin's plan.