In the ending of Puss in Boots (2011), Humpty Alexander Dumpty sacrifices himself to save the gosling, the Great Terror takes the golden egg back to the clouds, and San Ricardo welcomes Puss home. That choice repairs the betrayal that split Humpty from Puss, and it is the right shape for the story, since the whole film is built on a childhood debt and the fairest way to settle it is at a cost. Humpty set up the scheme to get revenge for being left behind, so protecting the gosling reverses his own motive.
The golden egg found inside Humpty's shell is the strangest beat. The Great Terror takes it back to her nest in the clouds, which returns the magic to where it came from and removes the prize that started the chase. In the epilogue, San Ricardo welcomes Puss back, he and Kitty Softpaws grow closer, Jack and Jill are left recovering, and Humpty is seen alive again, riding on the Great Terror's back.
It could be argued that the last image softens the sacrifice, but perhaps it also confirms that his redemption was real, since even the giant bird carries him. Humpty risks his life for the town, and the film lets him keep it.
Syfy Wire reports that Guillermo del Toro pushed for a rewritten ending that deepened the bond between Humpty and Puss, and Miller has called Humpty's believable redemption one of the hardest parts of the job. That context suggests the emotional beat was worked on deliberately. For younger viewers, Humpty's sacrifice is the scene to talk through afterward, and the PG rating is a fair guide to how heavy it feels.