Middle English, from Old English onforan, contraction of prepositional phrase on foran "before in place, at the beginning of, in front of," from on (prep.), see a- (1), + foran (adv.) "in front," dative of for. In some cases probably it represents Old English ætforan "at-fore."
Early 14c. as a preposition, "before in time," and as a conjunction, "earlier than the time when, before." Once the literary equivalent of before, it now has been replaced by that word except in nautical use, colloquial dialects, and in combinations such as aforesaid, aforethought.