Before Shrek and Donkey rescue Princess Fiona in the first film, King Harold and Queen Lillian – desperate to lift their daughter's curse – meet with con artistRumpelstiltskin, who wishes to become King of Far Far Away in exchange for helping them. But before the deal is contracted, the king and queen learn that Fiona has been rescued. Rumpelstiltskin is then shown to have become washed up as a result and subsequently bitter towards Shrek for inadvertently ruining his plans.
In the present, 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 snap and he smashes the new birthday cake in anger. He and Fiona argue outside about his reaction which ends with Shrek rashly agreed that he was happier before he'd rescued her.
After storming off, Shrek encounters Rumpelstiltskin. Rumpel, 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. Shrek helps him and Rumpel being "grateful", gives Shrek a ride and a meal. When Shrek voices his frustrations, Rumpel offers to give 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 R
umpelstiltskin, 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 asslave labor.
'Upon inquiry, Rumpelstiltskin reveals that the day he erased was the day that Shrek was born. 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 fade from existence. Shrek escapes Rumpelstiltskin's castle with Donkey. Initially terrified of Shrek, Donkey decides to trust him after seeing Shrek cry over his lost past, 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 and the lava from the crater under the castle has been drained. They soon encounter a band of ogres who are resisting Rumpelstiltskin. The ogr'es are led by Fiona, who is still cursed after escaping from the tower where she was held captive, and 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 the ogres being released. Fiona remains in custody because she is only an ogre by night (as Stiltskin himself points out). 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 the world to just before Shrek originally lashed out at everyone. Shrek embraces his friends and family with a newfound appreciation for everything he has, truly living happily ever after.