Old English gæst, giest (Anglian gest) "an accidental guest, a chance comer, a stranger," from Proto-Germanic *gastiz (source also of Old Frisian jest, Dutch gast, German Gast, Gothic gasts "guest," originally "stranger"), from PIE root *ghos-ti- "stranger, guest, host" (source also of Latin hostis, in earlier use "a stranger," in classical use "an enemy"); the root sense, according to Watkins, probably is "someone with whom one has reciprocal duties of hospitality."
Spelling evolution influenced by Old Norse cognate gestr (the usual sound changes from the Old English word would have yielded Modern English *yest). Meaning "person entertained for pay" (at an inn, etc.) is from late 13c. Old English also had cuma "stranger, guest," literally "a comer." Phrase be my guest in the sense of "go right ahead" first recorded 1955.