Treehouse of Horror XII is an anthology episode that features mini-stories. "Hex and the City" tells the story of how the Simpsons deal with a Gypsy's curse. In "House of Whacks," the Simpsons buy a computerized upgrade for their house, and the house develops an obsessive attraction to Marge. "Wiz Kids" is a Harry Potter parody about student wizards Bart and Lisa and an evil plot of the Dark Lord Montymort.
It's Halloween at the Burns Manor, and Smithers is up a ladder leaning against one of the towers, struggling to hang a small orange bat decoration on a lightning rod. At Burns' insistence, Smithers puts the bat at the very top, because, Burns says, it won't scare anyone if he hangs it any lower. Smithers succeeds, but slips and falls backwards off of the ladder. In a desperate attempt to keep from falling off of the roof, Smithers grabs an electrical cable and ends up sliding down it to the other tower, and then crashing into a high-voltage power box, which electrocutes him. The tower breaks in half and its upper portion falls over and hits the Burns family mausoleum, smashing it open and knocking four caskets out of the front. The caskets slide toward the front porch where they end up standing upright and open, revealing the corpses inside them.
Just then the trick-or-treating Simpsons walk up to the Burns manor in their Halloween costumes. Homer and Marge are dressed as Fred and Wilma Flintstone; Lisa and Maggie as conjoined twins; and Bart as a hobo. The family arrives just in time to see Smithers' body burst into flames, showering sparks which set the four caskets on fire. Frightened, the family scream and run back out through the closed gate, which cuts them into vertical slices. The slices of the Simpsons continue to scream and run away, scattering into the nearby woods. Burns, who has climbed up the ladder to the lightning rod, is pleased. He then pats the bat decoration, which comes to life and flies into the screen, revealing the title: "THE SIMPSONS HALLOWEEN SPECIAL XII".
The Simpsons are walking in Ethnictown, an immigrant neighborhood of Springfield. Marge and the kids see a fortune teller's shop and go in. The gypsy in the shop starts to tell Marge's fortune, but is interrupted by the late arrival of Homer, who calls the gypsy a fake and a fraud. Offended, the Gypsy tells Homer to leave, but on his way out he's freaked out by the beads in the doorway, flails about all over the place, knocks over some lit candles, and sets himself on fire. Homer rolls around trying to put the flames out, and the sprinklers (set off by the fires) trash the Gypsy's office by drenching everything in it, also bringing the Gypsy's collection of shruken heads back to life. Now enraged, the Gypsy places a curse on Homer, telling him that he will bring bad luck to everyone he loves. Homer scoffs at the curse, but Marge warns him that the Gypsy's curse could mean his family.
Marge's warning is proven correct the very next morning, when she wakes up with a beard and mustache, to the family's shock. Lisa turns increasingly into a centaur and Maggie into a ladybug (but still with a human head), while Bart's neck, after a strangling from Homer, becomes so long that he can't hold his head up anymore.
Homer goes to Moe's Tavern for advice, and Moe suggests that Homer capture a Leprechaun to get rid of the curse. Homer continues to deny that he's been cursed, but immediately, a helicopter crashes through the roof, killing Lenny and Carl, and Moe ends up stuffed into his own suddenly-oversized pickled egg jar, to Homer's surprise ("When did that happen?"). Homer and Bart dig a trap, planning to bait it with Lucky Charms to capture a Leprechaun, but on his first attempt catches only rabbits because he accidentally uses Trix for bait. Homer succeeds on the second attempt (after using the right bait) and takes the Leprechaun home, but all it does is run amuck and trash the house. Bart becomes tired of trying to hold his head up and drowns in his cereal; the Leprechaun, uncaring, dances on his head. Lisa then suggests that Homer sic the Leprechaun on the Gypsy. Homer takes Lisa's advice, returning to the Gypsy's shop and setting the Leprechaun loose on her. Initially, it seems to be working, as the two of them roll around on the floor fighting. But very quickly, to Homer's disgust, the fighting and scratching turn to kissing and fondling, as they've fallen in love.
The Gypsy and the Leprechaun decide to get married, and attending the wedding are other gypsies, assorted mythical creatures, Kang and Kodos, and Homer and Marge (now completely covered with hair). Yoda, officiating, pronounces the Gypsy and Leprechaun husband and wife, and Homer comments that everything worked out for the best. Marge, shocked and now entirely covered in blue body hair, reminds Homer that Bart is dead, but an apology from Homer would bring him back (according to the Gypsy). Homer stubbornly refuses: "She's not the boss of me."
Marge opens the door to a high-pressure salesbot which makes its pitch for the Ultrahouse 3000. The salesbot clinches the sale when it tells Marge that she'll neverhave to do housework again. Two other robots come over to install the Ultrahouse, and the Simpson home ends up looking like it's had a high-tech makeover, with a sleek, shiny, futuristic look and red camera lenses scattered around. Marge doesn't like the Ultrahouse's standard mechanical voice, so she and Bart and Lisa explore the other voice options and settle on having it use Pierce Brosnan, one of the many actors to play James Bond.
The Simpsons are quite impressed with the Ultrahouse. It freshens the house to smell like lilac (using its sensors to determine that Bart likes the smell), summons them to dinner with a laser-beam triangle, serves their favorite foods (which it determined from analyzing their bathroom "leavings"), and even does all the after-dinner washing up: The table's ends lift up (making a "V" shape with the table's center at the bottom), and streams of water clean the dishes and wash all the meal-related debris down a garbage disposal in the center of the table.
After dinner, the Ultrahouse seems to be taken with Marge, watching her get into the bathtub (to her initial embarrassment), lighting candles in the bathroom for her, and turning on the tub's bubbles, which she enjoys. Meanwhile, in the living room, the Ultrahouse serves Homer beer (and tests his blood alcohol level) and talks with him about what a remarkable woman Marge is and how lucky he is to have her. Homer replies that luck had nothing to do with it; Marge had to marry him because he knocked her up, and now she's stuck with him until "death do us part". He then states that if he were to die, she'd be free for man or machine. The Ultrahouse takes note of his foolish remark and plans a scheme.
Later that night, the Ultrahouse says to itself, "Showtime," and goes into action, frying bacon in the kitchen. The smell of the "unexplained bacon" lures a half-asleep Homer into the kitchen, where ice cubes fall out of the refrigerator onto the floor in front of him, making him slip and fall onto the dining room table. Then the ends of the table lift up, sliding Homer into the garbage disposal. Blood splatters all over the kitchen.
The next morning, Marge wakes up to notice that Homer is gone. The Ultrahouse says it thinks that Homer went to work early, which makes her suspicious: "That sounds like a lie." She then notices on a family portrait that Homer's face has been replaced by one of the Ultrahouse's camera lenses. She calls the police to report that she suspects the house of murdering her husband. The Ultrahouse's Pierce Brosnan voice answers, claims to be the police, and tells her to remove her knickers and wait in the bath. Marge then realizes that trouble is afoot. She grabs the kids and makes a run for the front door. The Ultrahouse closes the front door, trapping Marge and the kids inside, and they retreat to the kitchen, where they are frightened by a blood-covered fist punching up through the floor. It turns out to be Homer coming to the rescue, although the back of his head is missing and his brain is exposed. Surprised that Homer survived the garbage disposal, the Ultrahouse makes assorted tools come out of the walls to attack him and makes the floor disappear one tile at a time, attempting to finish him off. Homer dodges the tools and escapes with the rest of the family into the basement, where they go after the Ultrahouse's central processor. Homer grabs an axe and smashes what he thinks is the Ultrahouse's CPU, but Lisa tells him that it is the tank for the water softener. Homer says,"Well, I am missing the back of my head, I think you could cut me some slack." Homer finds the Ultrahouse CPU, opens the front panel and removes its circuit boards, rendering the Ultrahouse powerless. As Marge and Lisa take the remains of the Ultrahouse out with the trash, Marge comments on the waste. Lisa says, "There must be someone who can use a man around the house... even if if he's slightly homicidal."
The scene shifts to Patty's and Selma's apartment, where the re-assembled Ultrahouse CPU has been set up in the living room. As Patty tells a seemingly endless story about her day at work, the Ultrahouse rummages around on its exterior, finding an empty space with two cut-off wires. Selma coyly says, "Looking for this?" and holds up the self-destruct button. As the Ultrahouse makes a grab for the button, Selma hides it down the front of her dress, to the Ultrahouse's revulsion. Not wanting to listen to any more of Patty's story, and unwilling to go fishing in Selma's cleavage for the self-destruct button, the Ultrahouse grabs their Egyptian pyramid lamp and starts beating itself to death.
Bart and Lisa are students at the Springwart's School of Magicry, where Mrs. Krabappel tells the students (one of whom is Harry Potter) that because the big magic recital is coming up, they're going to practice toad-to-prince spells. Milhouse turns his toad into a drunken, loutish man who hits on Mrs. Krabappel. Lisa, as good at magic as she is at school work turns her toad into a hardsome young prince whom Mrs. Krabappel hits on. Bart is also as good at magic as he is at schoolwork whose toad becomes a hideous toad-prince creature which constantly vomits and begs Bart to kill him. Mrs. Krabappel praises Lisa's work, describing her as "casting spells at an eighth-grade level", but sharply criticizes Bart: "You've sinned against nature." Bart and Lisa begin to argue, but Lisa uses the "Head Zeppelin" spell to turn Bart's head into a Zeppelin and float him around the classroom, prompting the whole class to laugh at him.
Meanwhile, Lord Montymort is spying on the classroom from his lair. Seeing Lisa's abilities, he tells his snake assistant Slithers that he wants to capture her and steal her magical essence, as he's not getting anything from Ralph Wiggum, whom Montymort captured previously. Ralph and Montymort are wearing identical helmets which are connected by a tube, and lumps of "magical essence" are going from Ralph to Montymort. The key to capturing Lisa, claims Montymort, is to separate her from her wand, and for that, he'll need the help of an outside party.
Back at school, Bart is using the hand drier in the boy wizards' bathroom when it sucks him into the wall and deposits him in Montymort's lair. Montymort proposes that Bart help him capture Lisa, and in return he'll get to see her publicly humiliated. Out of jealousy and spite, Bart readily agrees.
The scene shifts to the Springwart's Magic Recital. Principal Skinner announces that Lisa will be performing the "levitating dragon trick". Meanwhile, Bart is backstage, stealing Lisa's wand and leaving a licorice Twizzler in its place, before sneaking away. The curtain goes up, and Lisa orders stagehands Jimbo and Kearney to release the dragon. As the dragon roars and breathes fire, Lisa picks up her wand and calmly says the levitation charm, but nothing happens. Then she realizes her wand is a licorice stick, and sees Bart backstage laughing evilly. The dragon now reveals its true colors and morphs into a giant Montymort, who grabs Lisa and puts the connected helmets onto her head and his own. As the lumps of magical essence start flowing from Lisa to Montymort, Lisa calls to Bart for help. Now remorseful, Bart casts a spell with Lisa's wand: "Prank be undone! Destroy the evil one!" However (possibly due to his not being specific enough), the spell zaps Bart instead of Montymort, scorching Bart and charring the wand.
Giving up on magic for the moment, Bart charges at Montymort and stabs him in the shin with the charred wand. As it turns out, he's found Montymort's one weakness: his enchanted shin, the source of his power. Montymort shrinks to normal size and dies, and Slithers eats him whole in typical snake fashion, crying all the while.
Bart and Lisa agree to stop their rivalry and try to put the nightmare behind them. As they walk away and the scene fades out, the Leprechaun from "Hex and the City" jumps from out of nowhere onto Bart's back and hitches a ride—chuckling crazily to himself, looking directly into the camera, and shushing the audience.
As the closing credits roll, Pierce Brosnan, the Leprechaun, and Bart's toad-prince from "Wiz Kids" emerge from the guest stars' trailer carrying baskets of fruit. Brosnan is impressed that they get to keep the fruit baskets. Brosnan's car is parked right outside the trailer, prompting the Leprechaun to sarcastically comment, "Mr. Movie Star gets to park right next to the stage!" As a peace offering, Brosnan asks if he can give the Leprechaun and the toad-prince a ride to their car, which they accept. After they all get in and Brosnan starts driving, Brosnan asks the Leprechaun where they're parked, and the Leprechaun replies that they don't have a car. Realizing he's been tricked, a surprised Brosnan starts to protest, and the Leprechaun says in a menacing voice to keep driving. The car suddenly speeds up, crashes through the studio gate, and cuts off several other vehicles as it turns into the street, with the Leprechaun cackling in a crazed fashion all the while—implying that even though Brosnan is still behind the wheel, the Leprechaun has somehow managed to seize control of the car.
The episode received positive reviews from TV critics, but mixed reviews from fans. Many fans were disappointed with the segment "Hex and the City," but found that the other segments greatly improved the episode and made up for the "rather boring start."