While waiting for the flood water in my basement to recede the other day, I watched an episode of PBS' Secrets of the Dead: S20E03 Decoding Hieroglyphics.
The episode explores the vast numbers of hieroglyphics covering all the walls of tomb TT33 (Theban tomb 33), the tomb of Padiamenope, a royal scribe, lector priest, and master of religious ceremonies. His tomb is the largest burial tomb in Egypt's entire Valley of the Dead -- bigger than any of the pharaohs.
All quotes below are from episode narration or participants.
In one section of his tomb, hieroglyphics retell the story of the Egyptian god Ra... but "on the walls of his tomb, Padiamenope inserted himself into the story of Ra."
Ra, the sun god, has to fight forces of the night that try to keep him from getting through the night to morning... But in the hieroglyphics telling the story, Padiamenope helps Ra fight - "placing himself in the deity's boat" - so Ra won't be imprisoned by the forces of the night forever and will rise in the morning like the sun is supposed to.
"Padiamenope is actively involved, hauling the sun god's boat, harpooning Apophis [the serpent trying to stop Ra's boat]. He's very actively involved in the journey, and even performs a ritual dance for the sun god."
"According to the text, if during the night, Padiamenope is unable to bring the sun god's boat home safely, the sun will not rise and the world will end."
"Padiamenope's version [of Ra's story] is very original. Into the sacred text, he inserts his own name and title. So there's the presence of the man of letters but also the desire to promote himself" -- even though in the original myth, which long predates him, Padiamenope has no role.
In a different section of his tomb, dedicated to the texts of the Egyptian Book of the Dead, Padiamenope is there during the ceremony of the weighing of the heart in the underworld.*
Padiamenope's tomb dates from approximately 700 BCE. So I think this is the most ancient Mary Sue fanfic. As a priest, Padiamenope would have been schooled in all the religious texts and rituals. Retelling the text stories with himself in them is essentially fanfic -- although by writing his own name all over his tomb walls, included in the telling of existing Egyptian myths, Padiamenope meant to ensure his place in the afterlife.
It's a really great episode (credits courtesy IMDb.com) of Secrets of the Dead.
*Anubis, who guides the dead after they die, puts an ostrich feather from the goddess Ammut on one side of the balance, and the deceased's heart on the other. If the person's heart is impure -- if he has committed any evil acts during life -- the heart will weigh more than the feather, Ammut will eat it, and the deceased soul cannot live in the afterlife. If, however, the heart weighs the same as the feather, or is lighter, this is evidence of a pure heart, one unencumbered by evil deeds -- and the deceased's soul proceeds into the afterlife, to live on forever. Thoth, god of wisdom and writing, records the result of the weighing of the heart. Osiris, god of the dead, presides over the entire ceremony. And this is why, although they removed all other organs, Egyptian embalmers put the deceased's heart back into the body before mummification: so that it could be weighed in the journey to the afterlife.