To tackle misbehavior, Principal Skinner opens a CTU – Counter Truancy Unit – at Springfield Elementary School with Lisa heading up the operation over Milhouse, Martin and Database. When the bullies Jimbo, Dolph and Kearney play truant, Milhouse is assigned on a mission to spy on them. At the Power Plant, Homer is found to be the owner of a container of expired and highly pungent yogurt and is ordered to dispose of it. Homer tries to return the yogurt to Apu, but Apu refuses to take it due to its unbearable stench and, desperate to get rid of it, takes Homer to the yogurt section and offers him whatever he wants there. While Homer and Apu are distracted, the bullies take the yogurt. Outside, Homer unwittingly breaks Milhouse's cover, and the bullies throw them both in a trash container and send it rolling down an avenue.
Meanwhile, Marge discovers that there is a bake sale at the school that day, and realizes she has just 27 minutes to make a cake. In order to save time, she drastically increases the oven temperature to 1,200 degrees, quickly burning the cake and making it rock-solid. Marge desperately attempts to cover it up with pink and white frosting before rushing to the bake sale.
Lisa suggests that Bart help them, though he only agrees after negotiating immunity from punishment for all his past and future pranks (and making Skinner teach him a new swear word). At Jimbo's house, the bullies make a powerful stink bomb (which resembles the canisters of Sentox Nerve Gas from season 5 of 24) from the expired yogurt and a variety of other putrid items, and plan on detonating it at the bake sale. During his investigation, Bart's phone call is accidentally crossed with a call from Jack Bauer of 24, who is busy in a gun battle, and turns it into a prank call against him ("Ahmed Adoudi").
Bart finds out about the stink bomb and informs Lisa. Upon returning to school, he discovers that Martin is a double-agent working for the bullies. Before Bart can tell Lisa about Martin's double-dealing, Martin knocks him unconscious and takes him to the ventilation room, where the bullies tie up Bart. When Willie stumbles upon the bullies, they overpower him and tie him up too. The bullies then return Martin's ant farm, which they had used to blackmail him into working for them, but Martin is devastated to learn one of their ants has joined the bullies' cause. Later, he hangs himself by his underwear on a clothing hook, giving himself a wedgie after putting on his hall monitor sash (as an homage to the suicide in A Few Good Men as well as that of the character Walt Cummings on Season 5 of 24, who is murdered and has his death framed as a hanging).
At the bake sale, the bullies start the three-minute timer for the bomb. Bart, still tied up, manages to contact Lisa by his cell phone, telling her to have Skinner dump the hot dog water to short circuit the ventilation fan. Skinner starts filling up the room with the water. Running out of air and floating dangerously close to the sharp ceiling fan blades, Bart swims down with the chair tied to his back to the room's only window, which faces the bake sale room. Chief Wiggum is unable to shoot through the bulletproof glass, but Marge then throws her burnt cake like a discus through the window, breaking the windows and allowing Bart, Willie, the bomb, and all the water to flood into the room. Lisa defuses the bomb with one second to spare. Bauer and his CTU SWAT Team then arrive to arrest Bart for prank-calling him, having diverted all CTU's resources into finding him. As he says that, a nuclear bomb explodes in the distance, but to the crowd's relief Bauer assures them that it went off in neighboring Shelbyville.