Homer becomes jealous over Ned's incredible string of good luck. Homer chooses to pray just like Ned so God can reward him with such fortunate luck as well.
At a WNBA game, Homer notices that things always seem to turn out for the best for Ned. Ned wins $100,000 as a reward for donating $50,000 he won in a contest. Ned then gets to drive home in a food shaped car which makes Homer even more jealous. Homer then tries to find out Ned's secret and why he keeps getting good luck.
Homer decides to directly ask Ned about his luck and as to what he is doing differently than others. Ned reveals a bunch of actual useful things and adds praying to God at the end. Homer then turns to prayer in order to get what he wants after Ned tells him that its one of his secrets to success, (technically, he said it was a small part together with hard work and clean living which Homer ignored in favor of the part that required no effort).
Homer then starts praying to God for everything. After Homer's walls start cracking, he prays for God to help him get money to fix it. On the way past the First Church of Springfield he falls into a hole. Larry H. Lawyer, Jr. wins his case and Homer is awarded the deed. Homer starts committing increasingly blasphemous acts, from throwing out AA members to throwing a three-day party that ends up breaking every commandment in the book. Matters go disastrously wrong in the form of a massive flood. Fortunately, Reverend Lovejoy shows up at the last minute and pleads to God to not punish the town, claiming they were mislead by a "Demon in Blue Pants."