late Old English agan, from earlier ongean "toward, opposite, against, in exchange for," from on "on" (see on) + -gegn "against, toward," compounded for a sense of "lined up facing, opposite," and "in the opposite direction, returning." For -gegn, cf. Old Norse gegn "straight, direct;" Danish igen "against;" Old Frisian jen, Old High German gegin, German gegen "against, toward," entgegen "against, in opposition to."
In Old English, eft was the main word for "again" (see eftsoons), but this often was strengthened by ongean, which became the principal word by 13c. Norse influence is responsible for the hard -g-. Differentiated from against 16c. in southern writers, again becoming an adverb only, and against taking over as preposition and conjunction, but again clung to all senses in northern and Scottish dialect (where against was not adopted).