1520s, "obtain as profit," from French gagner, from Old French gaaignier "to earn, gain; trade; capture, win," also "work in the fields, cultivate land," from Frankish *waidanjan "hunt, forage," also "graze, pasture," from Proto-Germanic *waithanjan "to hunt, plunder," from *waithjo- "pursuit, hunting" (source also of Old English waþ "hunting," German Weide "pasture, pasturage," Old Norse veiðr "hunting, fishing, catch of fish").
This is from PIE root *weie- "to go after, strive after, pursue vigorously, desire," with noun derivatives indicating "force, power" (related to *wi-ro- "man;" see virile). Cognates include Sanskrit padavi- "track, path, trail," veti- "follows, strives, leads, drives;" Avestan vateiti "follows, hunts;" Greek hiemai "move oneself forward, strive, desire;" Lithuanian vyti "to chase, pursue;" Old Norse veiðr "chase, hunting, fishing;" Old English OE wað "a chase, hunt."
Meaning "obtain by effort or striving" is from 1540s; intransitive sense of "profit, make gain" is from 1570s. Meaning "arrive at" is from c. 1600. Of timepieces by 1861. Related: Gained; gaining. To gain on "advance nearer" is from 1719. To gain ground (1620s) was originally military.