A millennium ago, Kaguya arrived from another world with her clan in search for fruit of the God Tree. In the anime she arrived alone and, upon her arrival, she was discovered by the people of the small Land of Ancestors, who brought her before their emperor, Tenji. Identifying herself as the God Tree's guardian, Kaguya used a mysterious power to wipe Tenji's memories of the encounter and subsequently settled among his people, becoming recognised as his concubine. Growing closer with the emperor, she eventually fell pregnant. When the Land of That began to threaten the Land of Ancestors over a border dispute, Tenji attempted to prevent the outbreak of war by declaring that anyone who attacked the larger nation's representatives was to be executed, a order which she broke when she was threatened by them, resulting in her and her assistant Aino becoming hunted by their land to be executed.
Losing all faith in humanity but still longing for peace, Kaguya believed that it was necessary for her to attain god-like powers in order to put an end to all of humanity's conflicts. For that reason, she defied the taboo of consuming the fruit of the God Tree. Using her new-found power, Kaguya single-handedly ended the wars. In the anime, she did this by casting the Infinite Tsukuyomi, and to ensure mankind didn't perish, Kaguya released some of the humans from the genjutsu and erased their memories.
For her deed of stopping the conflict, she was worshiped as the Rabbit Goddess. She later gave birth to twin sons, Hagoromo and Hamura. As time passed, however, Kaguya began to lose trust in humanity as the power she now held ultimately corrupted her, which changed her public image from that of a benevolent goddess into that of a Demon. This eventually led her to madness, committing acts such as turning victims of the Infinite Tsukuyomi into an army of White Zetsu, in preparation for Ōtsutsuki descendants from another world coming to Earth to steal her chakra for themselves. Information regarding this threat was written in a highly encrypted scroll, stored inside her palace within an ice dimension. In a fit of rage when her own sons betrayed her using the chakra they inherited from her, Kaguya combined with the God Tree itself and fought them in the form of the monstrous Ten-Tails in an attempt to reclaim the chakra she had given them.
The battle ended with Hagoromo and Hamura sealing the beast's chakra within the former's body while using its husk as the core of Six Paths — Chibaku Tensei, creating a celestial body that would become known as the moon. Hamura later took leadership of the Ōtsutsuki clan and departed to the moon to guard the beast's remains, while Hagoromo remained on Earth in order to spread chakra to humanity and teach them the concept of ninshū. However, just before her sons could completely seal her, Kaguya had manifested her will in the form of an artificial human called Black Zetsu. With the agenda of reviving its "mother", Black Zetsu manipulated Hagoromo's eldest son, Indra Ōtsutsuki, as well as his descendants within the Uchiha clan and his brother's descendants within the Senju clan in an attempt to get one of them to awaken the Rinnegan and break the seal. Madara Uchiha would eventually succeed in obtaining the Rinnegan, and Black Zetsu began secretly manipulating world events to have Kaguya revived.