After Shrek (voiced by Mike Myers) and Fiona (voiced by Cameron Diaz) come back from their honeymoon, they are invited to a royal ball thrown by Fiona's parents to celebrate their marriage, an event in which Shrek is reluctant to participate. Donkey (voiced by Eddie Murphy) appears, wanting to move in with them after a falling-out with Dragon, much to their consternation. They all travel to the kingdom of Far Far Away and meet Fiona's parents, King Harold and Queen Lillian (voiced by John Cleese and Julie Andrews), who are surprised by Fiona's choice of husband and her new appearance. Harold is repulsed and at a family dinner, he and Shrek get into a heated argument over how Shrek and Fiona will raise their family. Fiona, disgusted at their behavior, locks herself in her room, where she meets her Fairy Godmother (voiced by Jennifer Saunders), who is also startled by Fiona's new looks and marriage. Subsequently, King Harold is accosted by the Fairy Godmother and Prince Charming, her son (voiced by Rupert Everett). He had arranged with the Fairy Godmother that Charming would marry Fiona and they demand that he gets rid of Shrek. Shrek worries that he and Fiona aren't meant to be, particularly after finding a diary from her pre-teenager years and discovering that she was once very infatuated with Prince Charming. Harold arranges for Shrek and Donkey to join him on a hunting trip, which is really a trap to lure the two into the hands of an assassin, Puss in Boots (voiced by Antonio Banderas).
When Fiona realizes that Shrek left, she asks her father for help, but he replies that he always wanted the best for her and that she should think about that too. Puss is unable to defeat Shrek and reveals that he was paid by Harold. He asks to tag along as a way to make amends. Shrek decides to go to the Fairy Godmother for help. However, the Fairy Godmother states that ogres do not live "happily ever after" and refuses to assist him. Nonetheless, the three sneak into the Fairy Godmother's potion factory and steal a "Happily Ever After" potion that Shrek believes will ensure a happy ending for his marriage. Shrek and Donkey both drink the potion, which doesn't appear to work. They wait out the storm in a barn and Shrek and Donkey become dizzy and fall over into a deep sleep. The next morning the potion has taken effect: Shrek is now a handsome human, while Donkey has turned into a white stallion. In order to make the change permanent, Shrek must kiss Fiona by midnight. Shrek, Donkey, and Puss return to the castle to discover that the potion has also transformed Fiona back into her former human self. However, the Fairy Godmother, having learned of the potion's theft, sends Charming to the castle, where he poses as Shrek to win Fiona's love. Although Harold recognizes Charming for who he really is, he doesn't speak up. Shrek, heartbroken, lets Fiona go, believing she will be happier with Charming.
A few hours later, Shrek overhears Harold telling the Fairy Godmother that Fiona hasn't fallen for Charming. She gives him a love potion for Fiona, which will cause her to fall in love with the first person she kisses. Harold at first refuses, but the Fairy Godmother threatens to take away his own "Happily Ever After" if he does not listen to her. After hearing that Charming is the Fairy Godmother's son, the trio is noticed by the Fairy Godmother, who has them arrested by the royal guards and thrown into a dungeon. When the royal ball begins, several of Shrek's friends band together to free the trio (having seen their arrest via the Magic Mirror) and help Shrek stop the kiss. The Muffin Man helps them create a gigantic gingerbread man named Mongo, who breaks through the castle's defenses. However, he falls into the moat and then slowly dies. When Shrek arrives, Charming forcibly kisses Fiona, believing the potion has taken effect, but Fiona temporarily knocks him out with a headbutt. When the Fairy Godmother confronts Harold, he reveals that he drank the potion himself at the last minute, having realized Fiona's love for Shrek. The Fairy Godmother tries to kill Shrek, but Harold sacrifices himself to save the couple. The spell reflects off his armor and vanquishes the Fairy Godmother into a cloud of bubbles and tears; it also reverts Harold to his true form, that of the Frog Prince. Harold apologizes to Shrek and Fiona for everything he has done, and now realizes what is best for Fiona, giving them his blessing. Shrek forgives him, and Lillian tells Harold that she still loves him no matter what. When it is midnight, Shrek tells Fiona that if they kiss now, then their change will be permanent. But Fiona says that she wants what any other princess wants: to live happily ever after with the ogre she married. The clock chimes as the potion's effects wear off, with Donkey changing back as well, much to his chagrin. He cheers up as Shrek reassures him he still is a noble steed in his eyes. Finally, Puss and Donkey sing as the royal ball resumes celebrating the true newlyweds.
In a post-credits scene, Donkey complains to Puss about missing Dragon, and rejects his invitation to a night-cap at the "Kit-Kat Club." Suddenly, Dragon flies in, along with six "Dronkeys" that Donkey happily embraces as his "mutant babies," and Donkey and Dragon reconcile. Having a larger family, Donkey realizes, "I've gotta get a job!"