Mr. Burns throws an elaborate Fourth of July party for himself, forcing his employees to wait on him and perform a Broadway-style musical number without pay. When Homer, Lenny and Carl become frustrated, they break into Mr. Burns' wine cellar and become completely drunk. Mr. Burns discovers this and calls the police, but the police soon notice that Mr. Burns' mansion contains stolen artwork including The Concert by Vermeer. He is arrested and paraded through the streets of Springfield inside a bamboo cage, where he is jeered by the townspeople on his way to prison. He leaves a reluctant Waylon Smithers in charge.
In an attempt to blackmail the warden, who resembles the warden of The Shawshank Redemption, Burns takes out a hand-written note. Reading it, he says, "I'm sure the boys at the city desk would be interested to learn that you're addicted to... to... I can't read my own writing. But I'll tell you this, warden: it starts with 'H'." A guard asks, "Ham?" to which Burns replies, "It's clearly more than three letters!" He is taken away, and the warden, when alone in the room, gets a helium tank from the closet, saying, "Ain't nobody gonna take my H from me." Afterward, he is taken into the cells, where the prison itself also resembles that of The Shawshank Redemption, in that the layout is very similar, and the showers are close to those of the movie.
In prison, Mr. Burns is placed in a cell with another white-collar criminal, but then demands to be moved when he discovers his cellmate was educated at Dartmouth College and the University of Virginia. Burns soon finds himself in the company of a tough-looking felon (voiced by Kevin Michael Richardson) reminiscent of John Coffey in The Green Mile. The felon, a born-again Christian, convinces Burns to find religion. The man became a born-again Christian when an inmate gave the man the book Helter Skelter with its subject Charles Manson on the cover; since the man was illiterate he identified the picture as Christ and thus he became who he is. Another reference to Shawshank Redemption is that the felon tears a Rita Hayworth poster off the wall, uncovering a cross. He then "sucks" the evil, represented by green slime, out of Mr. Burns. The prison, first seen by Burns as a hell hole, now becomes a heaven hole: he joins the prison choir and a Beatles tribute band called "Stab Four" and reads the Holy Bible many times in the prison laundry while Sideshow Bob is being washed.
Meanwhile, Burns' assistant Smithers assumes management at the nuclear plant and attempts to show the plant employees that he is nothing like Mr. Burns by being kind and accommodating. But when he joins Homer, Lenny and Carl for beer at Moe's, he overhears the three friends making fun of him. Smithers realizes why Mr. Burns scorns humanity and his behavior quickly deteriorates into that of a tyrant.
Homer, Lenny and Carl decide to break Mr. Burns out of prison when they realize that Smithers's present behavior is even worse than that of Burns, even to the point of instead of releasing the hounds, he releases wolverines. The three disguise themselves as prison guards, sneak into the institution and remove Burns from his cell. Mr. Burns, however, does not want to leave because he believes he has found his spiritual home. When the cellmate tries to stop them from escaping, Mr. Burns realizes that he misses being a power figure and that his toilet-tank baptism did not purge away all of his inner evil, stating that he forgot to suck some evil from between his toes, which had then multiplied rapidly and made him "a bigger bastard than ever". But Mr. Burns also wonders genuinely why his cellmate helped him; he is told that after killing so many rich white men over the years, he figured he would do right by at least one of them. The two men decide they are not so different and part company. Burns uses his money to leave the prison system, and is once again at the helm of the nuclear power plant, although he hopes his friend will gain another disciple. Burns' former cellmate finds a new disciple in Fat Tony.
Meanwhile, Bart and Lisa are forced to play with one another when Marge goes shopping (she notes that the mall is deserted when the townspeople are rioting, as is the case with Burns' trip to prison). When the two fight over Lisa's ant farm, it breaks and Santa's Little Helper eats all but one of the ants. The experience brings Lisa and Bart closer together, and they name the ant Annie (as in Little Orphan Annie, as well as the layman's term ant itself). They care for her as they would a child, but realize that she is near death. They decide to release her, so she can live out her last days in the wild, but as soon as they let her go Santa's Little Helper eats Annie.