late 13c., peine, "the agony suffered by Christ;" c. 1300, "punishment," especially for a crime, "legal punishment of any sort" (including fines and monetary penalties); also "condition one feels when hurt, opposite of pleasure," including mental or emotional suffering, grief, distress; from Old French peine "difficulty, woe, suffering, punishment, Hell's torments" (11c.), from Latin poena "punishment, penalty, retribution, indemnification" (in Late Latin also "torment, hardship, suffering"), from Greek poine "retribution, penalty, quit-money for spilled blood," from PIE *kwei- "to pay, atone, compensate" (see penal).
The early "punishment" sense in English survives in phrase on pain of death. Also c. 1300 the word was used for the torments of eternal damnation after death. The sense of "exertion, effort" is from late 14c.; pains "great care taken (for some purpose), exertion or trouble taken in doing something" is recorded from 1520s.
Phrase give (someone) a pain "be annoying and irritating" is from 1908; as a noun, localized as pain in the neck (1924) and pain in the ass (1934), though this last might have gone long unrecorded and be the original sense and the others euphemisms. First record of pain-killer is from 1853.