After seeing a commercial where he could win a free tour of "Farmer Billy's Bacon" factory, Homer goes on a pursuit to find the golden ticket. He, however, only wins a silver ticket, which allows him to be the judge of the pig competition at the Springfield County Fair. At the fair, Lisa's entry in the place setting competition is wrecked by the Rich Texan, who then mocks her, which causes Homer to want to retaliate. Recalling a warning from Chief Wiggum that he will be arrested if he commits another assault felony, Homer disguises himself as a masked superhero, "The Pie Man", and throws a pie straight into the Rich Texan's face, leaving him humiliated and the crowd laughing. The next day, after Homer hears that the Comic Book Guy has ripped off Bart, he arrives as the Pie Man (with a newer look) and throws a pie in his face, humiliating him in front of Nichelle Nichols, whom the Comic Book Guy invited for tea and some chit chat, and then promptly leaves as soon as she sees his face with pie (saying she would not date William Shatner for the same reason).
As the days go by, the Pie Man becomes big news, pieing many of "Springfield's scoundrels". Springfield's citizens anticipate that the Pie Man will come to the opening ceremony for the new cosmetic surgery clinic, which Mayor Quimby has built in place of the previous occupant, the Springfield Children's Hospital. Chief Wiggum also has a trap planned for Pie Man, because he's upset that Pie Man is skipping the most important part of being the law ("bike safety lectures"). As expected, Pie Man arrives, but as the trap is sprung on him, Pie Man escapes, though not before being shot in the arm. He also saves Marge from being trampled by the panicking crowd and steals a kiss from her, which causes Marge to become infatuated with Pie Man.
Returning home and after prying the bullet out of his arm, Homer is exposed as the Pie Man by Lisa, who had suspected him to be the Pie Man after repeatedly getting his mail. Homer reveals his secret life in the "Pie Cave", which is just the basement, where Lisa pleads with Homer to stop his Pie Man persona before he gets more seriously hurt. Homer promises to stop.
Yet the next day at the power plant, Homer can't cope with Mr. Burns's bullying of him and his co-workers. After imagining a conversation with pies, Homer decides to be Pie Man one last time to get back at Burns. After pieing him, Homer tries to run off, but falls asleep on a couch right behind Burns. Captured by Burns and Smithers, Homer is exposed by Burns, who then promptly blackmails Homer to be his "personal hitman", to pie those that Mr. Burns hates, lest be ratted out to the police and being forced to do community service.
After pieing himself and later a Girl Scout selling cookies, Homer is asked by Burns to pie Tibetan Buddhism spiritual teacher, the Dalai Lama (because according to Mr. Burns "all his talk of peace and love is honking off my Red Chinese masters"). Appearing at the Dalai Lama's gathering, Homer sees Lisa is present and is stuck between breaking his promise to her and Burns' threat. Just as he prepares to pie the Lama, Homer stops and decides to reveal himself as the Pie Man. However, nobody believes Homer is the Pie Man due to his stupidity, even when he insists. Lisa then tells Homer that he had created a hero that he himself couldn't live up to. Accepting what she said, Homer takes Lisa home, relieved that he's finally free from Burns' control.
That night, Marge admits that she also knew Homer was the Pie Man, saying, "It was clearly you in that suit. You'd have to be an idiot not to see it from the start." Homer then stands on the roof, declaring that the Pie Man will return to help people who get mistreated, along with his new sidekick, The Cupcake Kid (Bart). Marge then asks them to clean out the gutters since they're already up on the roof, much to their irritation.