Answer: He sacrifices himself for the other ogres.
Rumpelstiltskin has offered a special contract of wish fulfillment to anyone who can bring Shrek in. Shrek himself collects on this contract, asking for the release of all other ogres as his wish. Rumpelstiltskin complies, but doesn't release Fiona because he says that she does not qualify, only being half ogre. Shrek's one day is just about up and he is beginning to disappear, because he never was born. Fiona kisses him and for a minute, it appears that she is too late. Then Puss notices that Fiona is still an ogre, after the sun has come up and everyone realizes that love's true kiss has broken her curse, and his contract with Rumpelstiltskin. Shrek is returned to the birthday party, happy for the life he has.