At a WNBA game, Homer notices that things always seem to turn out for the best for Ned. Ned gets a hundred thousand dollars as a reward for donating fifty thousand dollars he won at a basket shot. The mascot, Swish, which later turns out to be Gil Gunderson walks out and Moe proposes to it. Ned then gets to drive home in a food shaped car which makes Homer even more jealous. Adding insult to injury, Ned teases Homer saying that the steering wheel looks like an onion ring. Homer becomes increasingly jealous of Ned, trying to find out his secret. He then tries to observe Flanders by sitting on his swing in the back yard and a binocular. He then asks Marge why does Flanders have much greener grass then theirs; to which she responds that since homer always passes out in the backyard, grass stopped growing well.
Then Homer decides to directly ask Ned about his luck and as to what he's doing differently than others. Flanders 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 end 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.