The earliest fanfic I know of is the Aeneid. Which predates that text.
I would go with the Hurrian tale of Humbaba/Huwawa, a ferocious monster from the Epic of Gilgamesh that may have been the prototype of the Gorgon in later Greek legend. In this story, written in a tablet dated to the 13th century BC, Huwawa is actually the 'hero' instead of Gilgamesh. That sounds like fanfiction to me!