Once upon a time, there was a beautiful princess who had fallen under a curse that transformed her into an ogre every night at sundown. Her fairy godmother told her parents to lock her in a tower guarded by a dragon until her true love could rescue her and break her from the spell with his kiss. A man in armor, Prince Charming (also the narrator in the first scenes), is shown racing to the castle through adverse conditions, climbing to the Princess’ room -- only to find the Big Bad Wolf lounging in her bed and reading a magazine. Princess Fiona is already rescued, married, and on her honeymoon.
Shrek and Fiona return from their honeymoon to find Donkey in Shrek’s house, where they learn he and Dragon are having relationship problems so Donkey has moved out. Shrek disagrees, and as Donkey is thrown out, heralds from the kingdom of Far Far Away arrive to invite the Princess Fiona and Shrek to receive the blessing of her royal parents. Shrek balks and claims that her parents aren’t likely to accept him, but after a brief but heated argument, the couple and Donkey depart for Far Far Away.
King Harold (Fiona’s father) confirms Shrek’s fears and becomes extremely angry and upset when he discovers the truth about his daughter’s new husband. As Harold and wife Lillian settle down to go to sleep after a dinner argument, Fiona returns crying to her room. There, her Fairy Godmother appears, and after being somewhat surprised by Fiona’s ogre-like appearance, promises to make everything better. Shrek then appears and Godmother realizes what has happened, causing her to leave in something of a hurry.
Shortly thereafter, Harold is visited by the Fairy Godmother. She is angry with Harold for ‘allowing’ the marriage to take place (despite having had no control over it), and it is revealed that her son, Prince Charming, was supposed to marry Fiona as part of a deal between the Fairy Godmother and King Harold. As they stop at a fast food restaurant, the Fairy Godmother subtly suggest that Harold have Shrek killed, and Harold heads to an unsavory pub to hire a hitman.
Harold tricks Shrek into meeting him in the woods the following day, claiming he wishes to get a better start on their relationship. There, Shrek and Donkey are jumped by the King’s assassin, Puss in Boots. After Shrek foils Puss’ attack, but does not attack him in return, Puss swears his life to Shrek, in thanks for Shrek sparing him. Taking an idea from Fairy Godmother’s business card (which was left with Fiona), the three decide to head to the Fairy Godmother’s office, which turns out to be a huge factory. They walk in on the Fairy Godmother preparing a love potion, and are promptly dismissed after Fairy Godmother tells Shrek that there are no happy endings for ogres. Shrek and his friends disguise themselves as employees and break into the potion room. They set off an alarm and barely escape Fairy Godmother’s guards, but not before making off with a “Happily Ever After” potion.
Shrek, Donkey, and Puss begin walking back to Far Far Away, and after some discussion and the revelation that the drinker must kiss his true love by midnight to make the effects of the potion permanent, Donkey takes a test-drink to make sure it’s safe. After nothing immediately happens to Donkey, Shrek finishes off the bottle. It begins to rain and the three take shelter in a nearby building, where Shrek and Donkey collapse. Back at the castle, Fiona is worried about Shrek, who had left very early in the morning to meet Harold in the woods, and informs her parents she will find Shrek and they will go back to the swamp. However, she also collapses at the door of the castle and is taken to her room by her parents.
The following morning, Shrek, Donkey, and Fiona have all transformed: Shrek into a human, Donkey into a stunning white stallion, and Fiona into her original human appearance from the first movie. Shrek rides Donkey to Fiona’s parents' castle to greet her, but an unfortunate circumstance has them missing each other in the castle and Shrek makes his way to her room and she makes her way to the doors, by alternate routes. Inside Fiona’s room, the Fairy Godmother waits to stall Shrek, while Prince Charming introduces himself to Fiona as the new, transformed Shrek. Fiona is initially confused, but uneasily accepts this as truth. Shrek, forced to watch the scene from the window (in which he sees Charming hugging Fiona and her returning, then going inside with him) becomes dejected. He then takes the Fairy Godmother’s advice to let Fiona go and leaves.
Donkey, Shrek, and Puss are all sitting dejected at the Poison Apple (the pub where Harold hired Puss) when Shrek spots a cloaked Harold sneaking into a private meeting room. He, Donkey and Puss go outside to spy through the window. They find out that Harold is meeting with Charming and the Fairy Godmother, who explain that Harold must slip Fiona a love potion so that she can kiss Charming and make the potion permanent. Harold refuses until the Fairy Godmother threatens to take away his own “happily ever after”. Shrek, Donkey, and Puss watch quietly from outside the window, but Donkey blows their cover when Charming addresses Fairy Godmother as “mother,” causing Shrek and his friends to run. The Fairy Godmother proclaims them as bandits and thieves and sends men-at-arms after them.
Back at Shrek’s swamp, several characters from the first movie (the Three Blind Mice, the Three Little Pigs, the Big Bad Wolf, the Gingerbread man, and Pinnochio) are watching a “broadcast” of the red carpet at Fiona and Shrek’s royal wedding ball, using the Magic Mirror as a television. They catch a promo for an upcoming episode of “Knights,” which shows a white stallion, an orange cat, and a brown-haired man (Donkey, Puss, and Shrek, respectively) being chased and finally arrested. Shrek’s friends notice that as Shrek is thrown into the prison wagon, he identifies himself madly as Shrek and asks for Fiona. They then set out out to Far Far Away to rescue him.
Meanwhile, Fiona is nervous about the upcoming wedding ball, citing displeasure with the “changes” in Shrek. Harold brings two cups of tea to her room (one of which is laced with love potion) and has a heart-to-heart with her in which she explains that she loved the old, “ugly,” uncouth Shrek for who he was. As she reaches for a cup of tea, Harold stops her and takes the cup she was going to drink from, explaining that he needs the decaffeinated mug (it is initially unrevealed if he gave her the potion or not at this point).
Shrek’s friends show up to spring him, Donkey, and Puss from the dungeon, and they devise a plan to storm the castle and stop the royal ball. They head to Drury Lane where they have the Muffin Man make them a giant (though mentally simple) gingerbread man named Mongo. As Shrek rides Mongo to the castle to break in, Prince Charming begins dancing with Fiona and forcibly trying to kiss her (to activate the love potion), but she keeps rebuffing him. Shrek makes it into the castle (though Mongo is doused with boiling milk and falls into the moat), and lets the others in. Then, along with Puss and Donkey, Shrek races his way to the courtyard where the ball was taking place. The castle knights give chase, and Puss falls back to repay his debt to Shrek by holding them off so that Shrek may continue.
Just as Charming is about to kiss Fiona, Shrek arrives and stops them, enraging the Fairy Godmother. A struggle ensues in which many parties fumble to keep Fairy Godmother’s wand away from her, but Donkey and Puss get a hold of it. She uses a last dich manuver and tells Charming to kiss Fiona. It appears as though the love potion took effect, but Fiona headbutts Charming (revealing that Harold never gave her the potion).While Shrek and Fiona are reunited, Prince Charming gets a hold of the wand and tosses it to the Fairy Godmother, and she proceeds to turn on Shrek, claiming once again that there are no happy endings for ogres. She sends a bolt of magical energy at him, but King Harold dives in front and is hit instead, but the bolt also reflects off his reflective breastplate and strikes the Fairy Godmother, causing her to turn into dozens of bubbles that pop and rain on the ground. King Harold is transformed into a bullfrog, and reveals that he is the Frog Prince, whom the Fairy Godmother transformed into a human years ago so that he could win the love of Queen Lillian, and apologizes for his behavior and gives his royal blessing.
As the clock strikes midnight, Fiona tells Shrek that she loved him for who he was and that he didn’t need to change for her, so the potion wears off and they both transform back into ogres (and, to his dismay, Donkey turns back into a donkey). The movie, like its prequel, ends with a musical montage, with cast members (led by Puss and Donkey) sing and dance to Ricky Martin’s "Livin' La Vida Loca".
After part of the credits roll, Donkey is shown alone crying and singing “All By Myself”; Dragon appears with six flying dragon-donkey hybrid children, and the two are reconciled. After the screen turns black, Donkey comically says, "I gotta get a job".