Just as it seems the whole toy gang will inevitably fall into the incinerating pit and burn to death -for which they even hold hands together, like accepting her faith-, in comes a giant mechanic claw operated by the three-eyed Alien Trio and rescues them. Later on, they manage to hitchhike back to Andy's house at the back of the dumpster truck from the beginning -the one with the dump collector perpetually dancing to the tune of his earphones-; at the same time, Lotso gets found by another garbage collector, who endearingly recalls he used to own a teddy bear just like it, and ties the toy to the front of his dilapidated truck, to his tremendous dismay.
The toys make it back to Andy's house just as he has finished packing and ready to take off to go to college, and shares a tender moment with his mom; although they were all ready to be stored in the attic and Woody would be taken to college, Woody has a change of heart and decides that they all deserve a better fate; so, he writes a note, indicating Andy to drop this box at Bonnie's -the sweet little girl from Sunnyside-, which Andy does.
While at Bonnie's, when undoing the box to show the girl the treasure he was trusting her with, he comes to realize Woody was in the box too, to Bonnie's pleasure; he hesitates for a second, but finally obliges, and shares a sweet moment playing one last time with his toys along with Bonnie.
At the end of the movie, the whole toy gang is seen joyfully at their new life with little Bonnie, and then, the credits roll, showing Sunnyside Daycare transformed into a true haven for toys.
Thanks Dr. Mat!