late 14c., necessarie, "needed, required; essential, indispensable; such as must be, that cannot be otherwise; not voluntary or governed by chance or free will," from Old French necessaire "necessary, urgent, compelling" (13c.), and directly from Latin necessarius "unavoidable, indispensable, necessary," from necesse "unavoidable, indispensable," originally "no backing away," from ne- "not" (from PIE root *ne-) + cedere "to withdraw, go away, yield" (from PIE root *ked- "to go, yield").
The etymological sense is of that from which there is no evasion, that which is inevitable. Necessary house "privy" is from 1610s (compare Medieval Latin necessarium "a privy"). Necessary evil is from 1540s (the original reference was to "woman").