Either don't interact with the demon doll near the end of the game or don't reject picking it up. Don't explore where the lonely girl doesn't really want to and escape the chasm when offered the chance.
Temmie also made a guide of all the endings in the additional downloaded files that you could read.