Prince Charming performs onstage in a bar, vowing that he will become King of Far, Far Away and avenge the death of his mother, the Fairy Godmother. Meanwhile, King Harold is dying and his ogre son-in-law Shrek and daughter Princess Fiona are to become King and Queen of Far Far Away. Shrek, who is having difficulty serving as Regent during the King's medical leave, insists that an ogre as king is a bad idea and that there must be someone else for the job. Before dying, Harold tells Shrek that there is another heir: his nephew, Arthur Pendragon. Prince Charming goes to the Poison Apple tavern, where he persuades numerous fairy tale villains to fight for their "happily ever after" by appealing to their tragic defeats given in their stories. Shrek, Donkey and Puss in Boots set out to retrieve Arthur; as they are sailing away, Fiona yells to Shrek that she is pregnant, leaving Shrek somewhat shocked.
The trio journey to Worcestershire Academy, an elite boarding school, where they discover Arthur ("Artie", as he prefers to be called) is a scrawny 16-year old underachiever picked on by everyone. At the school pep rally, Shrek tells Artie he is going to be king of Far Far Away. Artie is excited until Donkey and Puss inadvertently frighten him by discussing the responsibilities of being king. Artie tries taking control of the ship and crashes it on an island, where they meet Artie's retired wizard teacher, Merlin.
Charming and the other villains attack the castle, but Wolfie, Pinocchio, Gingy, the Three Little Pigs and the Blind Mice stall them long enough for Fiona and her mother Queen Lilian to escape along with Snow White, Rapunzel, Cinderella, Sleeping Beauty and Doris the Ugly Stepsister. Unfortunately, one of the Pigs accidentally blurts out that Shrek has gone off to bring in Arthur, and Prince Charming sends off Captain Hook and his pirates to track down Shrek. Even worse, the ladies are captured when Rapunzel betrays them because she is in love with Charming.
Captain Hook and his pirates track Shrek and his friends to Merlin's island, where they attempt to capture Shrek alive and kill the others. Shrek and Artie send the villains running, but not before Hook mentions Charming and the takeover of Far Far Away. Concerned for his wife and future children, Shrek urges Artie to return to Worcestershire. Instead, Artie cons Merlin into using his magic to send them all to Far Far Away. The spell works, but accidentally causes Puss and Donkey to switch bodies. They find Charming and learn that he plans to kill Shrek in a play that night. Charming's men arrive, but Artie tricks the knights into not taking them into custody. They break into the castle during rehearsals for the play. Caught in Charming's dressing room, the four are taken captive.
Charming prepares to kill Artie, believing he is the next king. To save Artie's life, Shrek tells Charming that Artie was a pawn to take his place as King of Far Far Away. Charming believes Shrek and allows Artie to run away. Donkey and Puss are imprisoned with Fiona and the princesses, where Fiona grows frustrated with their lack of initiative. Queen Lilian smashes the stone wall of the prison by head butting the walls. While the princesses launch a rescue mission for Shrek, Donkey and Puss free Gingy, Pinocchio, the wolf and pigs, Dragon and Donkey's children. They encounter Artie, and Puss and Donkey explain to him that Shrek lied so Charming would not kill him.
Charming stages a musical in which he rescues Rapunzel. Just as Charming is about to kill Shrek, Princess Fiona along with Puss, Donkey, the princesses and the fairy tale characters confront the villains. Artie convinces the villains to give up their evil ways, saying that just because they are being treated like losers doesn't mean that they have be losers.
Touched, the villains agree to give up their evil ways, except for Charming, who is furious at being thwarted. He attempts to lunge for Artie with his sword, but Shrek blocks the blow, so Charming lunges at him instead. Shrek, who at first seems fatally injured, informs Charming that he missed and that the Prince needs to keep looking for his own happily ever after. As Shrek pushes him aside, Dragon knocks Rapunzel's tower on Charming, presumably killing him. Shrek then tells Artie the throne is his if he wants it, and Artie decides to accept it. While the kingdom celebrates, Merlin restores Puss and Donkey to their proper bodies, accidentally switching their tails temporarily. Shrek retires with Fiona to their swamp, becoming the parents of ogre triplets.