NOTE: This spoiler sent in by Jackie Funshine
The movie begins with Prince Charming riding on a steed through a forest to rescue his beloved princess. However, the camera pans back and we see that the "forest" is actually a screen being rolled by two dwarfs and his "horse" is made out of wood. Prince Charming has been reduced to acting at a dinner-theater and none of the audience members are pleased. The set is falling apart and worst of all, everyone is cheering for Shrek when the final scene falls. Charming storms off the stage and into his dressing room, which is really just a mirror and a table in the alley outside. Frustrated and angry, Charming glares at his reflection. He hadn't gotten his "happily ever after" and that just isn't fair. Looking at a picture of his long gone mother, Charming starts to concoct a plan to avenge their honor.
Meanwhile, the King has fallen ill in Far Far Away and Shrek and Fiona have been summoned to take his place for a few days. We are given a glimpse at how bad Shrek is at being king. For example, he cuts a man while trying to knight him, sinks a ship as it's preparing to sail, etc. Shrek is given a makeover in hopes of at least looking the part, but he still ends up looking like a wolf in sheep's clothing. Shrek's only hope is that this won't last much longer. He tells Fiona how much he's looking forward to going back to their swamp, just the two of them. Fiona tells him that she's hoping for a few more too. After a few wrong guesses, Shrek learns that Fiona wants to have kids. Shrek thinks about his friends' children (Donkey has some little dragon-donkey hybrids with his wife) and tells Fiona that babies are not his kind of thing.
Unfortunately, the King is soon on his death bed. With his final breaths, he tells Shrek that there is only one other heir: Arthur Pendragon. He knows that Shrek would be a good king anyway, but that no matter what he chooses, it will be the right thing. The entire kingdom is in mourning of their king, and Shrek soon sets out to find the heir. As they're sailing off, Fiona runs to the dock and tells Shrek that she's pregnant. Shrek is shocked and has several nightmares about his future children. Everyone assures him that fatherhood is a great thing, but Shrek is not so sure.
When they finally arrive, Shrek finds that Arthur is only in high school. We see a bunch of teenagers fairy-tale-style. Unfortunately, this doesn't make Arthur any less of a "loser". Even the kids playing the medieval version of Dungeons and Dragons pick on him. When Shrek announces to everyone that Arthur is going to be king, the other kids only laugh. Arthur is feeling good about his new role until Donkey and the Puss in Boots scare him with responsibilities. Arthur gets into an argument with Shrek and they fight over the ship. They end up crashing on an island, where they meet Arthur's old magic teacher, Merlin. Merlin was fired after he had a nervous breakdown, and now he has to stay in touch with nature and his inner self more. In order to help Shrek and Arthur reconcile, he makes them look into a thick smoke to reveal their thoughts. Shrek sees a baby carriage, but pretends that he saw a "Rainbow Pony". Merlin is pleased and moves on to Arthur, who sees a bird and its father. The father bird abandons the chick, leaving him frightened and confused. Merlin tells the boy he's a nutcase and retreats to his hut.
Shrek decides to take this opportunity to show Arthur that they're not so different after all. Just as Arthur's father abandoned him, Shrek's father was pretty bad too. In fact, he tried to eat him. Shrek also tells Arthur that just because someone calls you "a monster or a loser, it doesn't mean you are one". Shrek tells him that people told him for years that he was horrible and terrifying, and for years, he believed them. Now, he's learned to just be who he wants to be. Arthur laughs with Shrek and they become friends again.
Meanwhile, Prince Charming has gone to the tavern where all the fairy tale villains go after they've been defeated. He convinces them to join him in a fight for "Their Happily Ever After". The villains feel like their side of the story has never been told and now is the time to do it. Fiona is still at the castle with her friends: Rapunzel, Cinderella, Sleeping Beauty, and Snow White. At the baby shower, Cinderella gives her a "baby poop scooper", Snow White gives her a baby sitter (it's one of the dwarfs), and everyone else just gives her advice (?). Suddenly, Prince Charming arrives and crashes the kingdom. Fiona and her friends escape just in time, but the other citizens are not as lucky. The entire kingdom is thrown into chaos and the villains take over the city.
The Three Little Pigs, the Wolf, the Gingerbread Man, and Pinocchio are still in the princesses' tea room, trying to seem normal. When Charming demands to know where Fiona and Shrek are, everyone manages to avoid the question (Gingerbread starts singing hysterically, Pinocchio talks in circles, and the Wolf just stays calm), but one of the Three Little Pigs breaks down and squeals (No pun intended). Charming decides to send some of his men to hunt down Shrek for a final showdown.
Shrek and Arthur wake up to find themselves surrounded by the villains sent by Charming. Working as a team, the group manages to frighten the villains away, but it doesn't bring them any closer to Far Far Away. Arthur decides to ask Merlin, and he whips out some acting skills to convince the old man. Merlin warns them that although the spell should work, there may be some minor side effects. Before he gets a chance to fully explain, they are zapped into Far Far Away. The side effects are minor, with Puss in Boots and Donkey switching bodies.
Fiona and the girls are still navigating the underground tunnels of the palace, but Rapunzel betrays them to become the new queen. The remaining girls are imprisoned, but Fiona's mother teaches them to be independent and breaks them out of the prison. They return to the castle and save the city from Charming's schemes.
Shrek arrives at the city to find everything in complete disarray. Pinocchio has been imprisoned as a marionette doll, but he manages to give Shrek some information on what has happened since he left. Charming is bent on revenge against Shrek for "stealing" his Happily Ever After and plans to kill Shrek in a play later that night. Shrek sneaks into Charming's dressing room, but Charming's men arrive shortly and quickly capture everyone. In an effort to save Arthur, Shrek tells Arthur that he wasn't the true heir, he was just a loser who could easily take Shrek's place. Thinking that Shrek is serious, Charming and Arthur are stunned. Arthur storms off and Charming returns to the important task of getting rid of Shrek.
Charming's play is significantly better than the one he participated in at the dinner-theater, but the audiences still cheer when Shrek is led onto the stage. Just as Charming is about to kill Shrek and rid himself of the humiliation he's suffered, Fiona and her friends leap onto the stage. They quickly defeat the villains imprisoning Shrek, but Charming just summons more.
Arthur has been convinced by Donkey and Puss in Boots to return after they explained what Shrek's true intentions were, and he manages to convince the rest of the villains that they don't need to do this. He tells them about the speech that Shrek gave them, and the villains decide that they don't need to be the villains anymore. Unfortunately, Charming doesn't feel the same way and Shrek has to use force. Donkey's dragon-wife knocks down a tower and Charming is crushed underneath.
Shrek offers Arthur the crown again, but this time it's up to Arthur whether or not he wants to take it. Shrek will no longer throw away his own responsibilities to someone else who is just as unsure as he is. Arthur picks up the crown and smiles at the crowd. Fiona and Shrek are reunited at last and Arthur already looks like he's popular with his new subjects.
Donkey and Puss in Boots go to seek Merlin once again, and he manages to reverse the body-switching spell, but their tails are still mismatched. Merlin starts to tell them, thinks better of it, and waltzes off.
A few months later, Shrek and Fiona are happily back in their swamp with their many ogre children. It's not as bad as Shrek thought it would be, although both of them are completely exhausted by the end of the day. The film ends with the children playing around with Donkey and the swamp creatures.