late 14c., "mental suffering" (especially that of Christ in the Garden of Gethsemane), from Old French agonie, agoine "anguish, terror, death agony" (14c.), and directly from Late Latin agonia, from Greek agonia "a struggle for victory" (in wrestling, etc.), in a general sense "exercise, gymnastics;" also of mental struggles, "agony, anguish." This is from agon "assembly, mass of people brought together," especially to watch the games, hence, "a contest," then, generally, "any struggle or trial;" from the verb agein "put in motion, move" (here specifically as "assemble, bring together"), from PIE root *ag- "to drive, draw out or forth, move."
Specifically of the struggle that precedes natural death (mortal agony) from 1540s. The sense development perhaps involves "pain so severe as to cause struggling." Sense of "extreme bodily suffering" first recorded c. 1600.