12c., agenes "in opposition to, adverse, hostile; in an opposite direction or position, in contact with, in front of, so as to meet," originally a southern variant of agan (prep.) "again" (see again), with adverbial genitive. The unetymological -t turned up mid-14c. and was standard by early 16c., perhaps from influence of superlatives (see amidst). The word's use as a conjunction, "against the time that," hence "before," is now archaic or obsolete.
<a href="https://www.etymonline.com/word/gainst">Etymology of gainst by etymonline</a>
Harper, D. (n.d.). Etymology of gainst. Online Etymology Dictionary. Retrieved $(datetime), from https://www.etymonline.com/word/gainst