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's 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. Things 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."