late 13c., "punishment," especially for a crime; also "condition one feels when hurt, opposite of pleasure," 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 earliest sense in English survives in phrase on pain of death.
Phrase to give (someone) a pain "be annoying and irritating" is from 1908; 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. Pains "great care taken (for some purpose)" is first recorded 1520s (in the singular in this sense, it is attested from c. 1300). First record of pain-killer is from 1853.