In the opening sequence, Marge talks about Halloween being "last week" and suddenly various logos for other Fox shows pop up on the screen, including the mini logos for American Idol, Fox Sports, Prison Break, Cops, House, and 24. Marge winds up killing several miniature characters that pop up from the logos (except the Prison Break one, which has the characters running away from the scene) and bakes them into meatloaf, which she serves to her family. When she cuts it, the other characters' body parts are shown to spell out the title, "Treehouse of Horror XVIII" and the opening credits (Homer eats the piece with the "developed by" credit, says "Mmmmmmm, developed by", and drools.)
In a parody of E.T. the Extra-Terrestrial, Marge tells Bart to get butane from their "butane storage shed" in the back yard. As he does so, he finds Kodos there. Kodos states his desire is to return home and that he had come to Earth in peace, though he hints that he was really sent there to destroy mankind. Bart, however, is oblivious to this, and decides to help him return home. Lisa arrives and is happy with the alien in their home and decides to help Bart and Kodos obtain a list of devices (including two tickets to see Avenue Q, Uranium, and "7 billion body bags") that he can use to contact his home planet, though this appears to be part of his diabolical plan. Homer discovers Kodos when the two accidentally share a shower, but he and Marge decide to let the kids help Kodos anyway, after Kodos hints it would be racist to turn him away (He said that they did not want him in the house because he was Jewish). When NASA agents arrive at the Simpsons home, Homer distracts them by dressing as Abraham Lincoln while Bart sneaks Kodos out. However, when Kodos kills several agents along the way, Bart begins to think Kodos's intentions are not as friendly as he was led to believe. Finally, Kodos reveals that the devices he had the Simpsons collect were for a portal-generating device so that others of her planet can come to Earth and wipe out the human race and eat their heads. When the aliens (including Kang) invade, the rest of the Simpson family shows up, along with the military. A brief war is waged, and Earth ultimately overpowers the aliens (the massive heads of Kodos' species make them easy targets for attack helicopters). When Bart is given the option to board a helicopter and shoot Kodos, Bart, seeing Kodos' smile, decides to spare him. However, Homer shoots Kodos several times. In the end, Earth emerges victorious and the world is saved. The Simpsons are invited to see Kodos's dissection, where they reflect that since Kodos was an evil-looking alien who turned out to be bad, it must be good to judge a book by its cover. It is revealed that Kodos is still very much alive, as he points what is happening is actually vivisection, only to be suffocated with a pillow by Homer.
In a parody of Mr. & Mrs. Smith, Homer and Marge are at a marriage counseling session, recounting a brief moment of tension between them.
In the flashback, when arriving home, Homer locks himself in the bathroom and communicates on a hidden flat screen television, where it is revealed Homer is an assassin assigned to eliminate news reporter, Kent Brockman, by order of Homer's boss, Mr. Burns. Although the bathroom is locked, Bart somehow got in and is sitting on a Mortar, which was the toilet. Before he leaves, he tells Marge he will be coming home late from "Midnight Monkey Madness." Marge also states that she is busy turning over wheelbarrows. When Homer prepares to shoot Brockman at his rooftop party from a faraway platform, a woman with large blonde hair (whom Homer dubs "the Mystery Skank") stabs Brockman in the chest. After Homer attempts to repeatedly shoot the woman (ending up with several civilian deaths), he manages to shoot the wig off her head, revealing the "mystery skank" to be Marge.
Arriving home, the two avoid each other's eyes, and Marge makes an excuse for the blonde wig. Unfortunately at dinner, Homer (thinking that he is talking in his head) exclaims "I'll kill her [Marge] after dessert!" which leads the two attempting to kill one another with various weapons such as grenades, rifles, and a minigun, all the while arguing why the other was an assassin, end up destroying most of their house, and killing Grampa Simpson. After killing Chief Wiggum with a crossbow, the two realize they are more attracted with one another when they kill someone together. For this, they soon begin making love over Chief Wiggum's body and, back to where the episode started, they both realized that they did not need any marriage counseling, but to kill people together. In the end, it turns out that the two were called into Principal Skinner's office to discuss Bart's misbehavior on the bus, with Skinner wondering why the two thought they were in a marriage counselor's office. The two promptly shoot Principal Skinner in the head as the scene cuts to black and the segment ends with Skinner's dying words, "think of me on pizza Fridays!" to which Homer responds "No."
On Halloween night, Bart (dressed as the Frankenstein's monster), Lisa (dressed as a witch), Milhouse (dressed as an astronaut) and Nelson (dressed as a hobo) become frustrated by Agnes Skinner refusing to give them candy, instead spitting into Milhouse's pumpkin, which was full of candy. Deciding to honor the true meaning of "trick-or-treat," they begin to pull pranks on everyone. Soon, however, their pranks turn into vandalism and everyone begins to complain. However Homer tells them to lighten up and says "it's halloween the night for mischief and merriment", but then a pig is thrown on him and then the camera turns up to the kids who are the ones who did it laugh and leave while everyone stares at them. Sideshow Mel shouts out loud "those monsters must be stopped". Ned Flanders then offers his services to teach them a lesson and fashions the church into a "heck house." This attracts their attention and they decide to give it a try.
Ned Flanders tries to simulate what could happen to them for their sins through the use of crude role-playing by Rod and Todd Flanders, but they scoff at his attempts. Ned then turns to God to give him the power to scare them into loving God and subsequently transforms into the Devil (reprising his role from "Treehouse of Horror IV"), sending the kids to Hell. There he brings up an enormous crystal ball revealing Springfield to be full of the Seven Deadly Sins, and shows them simulations of how they may suffer;
Hell is then shown with various people from Springfield who have punishments from their doings on Earth. The children resolve not to perform any of the sins again. Ned returns them back to the surface, reverting to his original form. The episode ends with Ned Flanders telling the viewers that they will go to Hell for watching this episode, along with Fox in general, as well as FX, Fox Sports and "the new devil's portal", The Wall Street Journal, which he welcomes to the "club".