c. 1300 BCE, though the text claims to be older
The Destruction of Mankind
Ra sends a goddess to punish humanity, then has to get her drunk to stop her finishing the job.
Ra has grown old, and humanity plots against him. He consults the other gods and sends out his Eye, in the form of the goddess Hathor, to punish them. She becomes Sekhmet, the lioness, and slaughters people across Egypt, wading in their blood.
Ra changes his mind. Humanity is nearly gone, and he wants what is left of it to survive. But the goddess cannot be recalled: she is his own power in action, and she is enjoying herself. So he has seven thousand jars of beer brewed and dyed red with ochre, and poured out over the fields overnight. At dawn she finds the flooded land, takes it for blood, drinks until she is too drunk to continue, and forgets what she was doing.
Ra then withdraws from the world, rising on the back of the sky-cow Nut to rule from a distance, and the direct rule of gods on earth ends. The text is followed in the tomb versions by a long stretch of ritual and cosmological material, including the sky-cow itself, which is why it is usually called the Book of the Heavenly Cow.
Then the majesty of Ra said: Call to me swift messengers, that they may run like the shadow of a body.
Where it comes from
The Book of the Heavenly Cow
Inscribed in New Kingdom royal tombs including those of Tutankhamun, Seti I and Ramesses II, c. 1300 BCE, though the composition is probably older.
What the story was for
Two things at once. It explains why the gods are no longer physically present and why the world has to be maintained by ritual rather than by their direct rule. And it explains a festival: the Egyptians drank heavily at the Festival of Drunkenness for Hathor, and this is the story that licenses it. The detail that the goddess who nearly ends humanity and the goddess of love and music are the same person is not a contradiction the Egyptians felt any need to resolve.
Other myths