Shrek has steadily grown tired of being a family man and celebrity among the local villagers, leading him to yearn for the days when he felt like a "real ogre". He takes his family to Far Far Away to celebrate his children's first birthday. Shrek gets annoyed when the Three Little Pigs eat the kids' cake along with most of the other party food. A boy named Butterpants (who is said to be a "big fan" of Shrek) demands that Shrek roar. After he lets out a frustrated roar the entire crowd cheers, reinforcing his belief that no one considers him to be a true ogre. This coupled with the fact that the birthday cakes were decorated with a "cute" ogre named Sprinkles finally makes Shrek lose his temper, smash the new cake in front of everyone, and walk out in anger. He and Fiona argue outside about his reaction which ends with Shrek rashly agreeing that he was happier before he'd rescued her.
After storming off, Shrek encounters Rumpelstiltskin, who had observed Shrek's angry outburst with Fiona, seizes his chance. He follows Shrek and arranges what appears to be an accident where he is trapped under his carriage. To "thank" him, he gives Shrek a day to live like a real ogre in exchange for a day from his childhood that he would not remember being erased. Shrek signs the contract and appears in a reality where he is still feared by villagers. He takes the opportunity to cause some light-hearted mischief until he finds wanted posters for the ogress Fiona and his home deserted and desolate. He is kidnapped by witches and taken to Rumpelstiltskin, now the King of Far Far Away and possibly Emperor of a good deal more, which has become derelict and run down. Rumpelstiltskin uses ogres (and some of Shrek's friends) for slavery.
Upon inquiry, Rumpelstiltskin reveals that the day he erased was the day of Shrek's birth. Therefore, Shrek never saved Fiona, never met Donkey, and consequently Rumpelstiltskin was able to get Harold and Lillian to sign their kingdom away, then cause them to disappear. When the day ends, Shrek will disappear as well. Shrek escapes Rumpelstiltskin's castle with Donkey. Initially terrified of Shrek, Donkey decides to trust him after seeing Shrek cry over his erased history, something he had never seen an ogre do before. After Shrek explains the situation, Donkey helps him find a loophole: the contract will be nullified if Shrek and Fiona share true love's kiss. Shrek and Donkey first travel to the dragon's keep where Fiona was kept and find the place deserted. They soon encounter a band of ogres who are resisting Rumpelstiltskin. The ogres are led by a still-cursed Fiona, who after escaping from the tower where she was held captive, keeps the retired and overweight Puss in Boots as a pet.
Shrek does everything he can to gain Fiona's love, but she is too busy preparing an ambush on Rumpelstiltskin. She is also bitterly cynical and disillusioned about the power of true love and throws herself into planning Rumpelstiltskin's capture. While sparring with her, Fiona begins to like Shrek, but stops short of kissing him. Shrek is discouraged, but Puss encourages him to continue pursuing Fiona.
During the ambush, the ogres are captured by the Pied Piper, though Shrek and Fiona managed to escape with the intervention of Puss and Donkey. Shrek insists Fiona kiss him, saying it will fix everything, but because Fiona does not truly love him it is ineffective. Upon hearing that Rumpelstiltskin is offering anything desired by the one who captures Shrek, Shrek surrenders himself in exchange for "all ogres" being released. Fiona remains in custody because, as Rumpelstiltskin points out, she is not "all ogre" (only by night, not by day). Shrek and Fiona are to be fed to Dragon, but Donkey, Puss and the ogres raid Rumpelstiltskin's castle, allowing Shrek and Fiona to both subdue Dragon and capture Rumpelstiltskin.
As the sun rises, Shrek begins to fade from existence. But Fiona, having fallen in love with him, kisses him just before he disappears, thereby voiding the contract and restoring Shrek to his world just before he originally lashed out at everyone. Shrek embraces his friends and family with a newfound appreciation for everything he has, truly living happily forever after.