Old English swerian "take an oath" (class VI strong verb; past tense swor, past participle sworen), from Proto-Germanic *swērjanan (source also of Old Saxon swerian, Old Frisian swera, Old Norse sverja, Danish sverge, Middle Dutch swaren, Old High German swerien, German schwören, Gothic swaren "to swear"), of uncertain origin, perhaps from a PIE *swer- "to speak, talk, say" (source also of Old Church Slavonic svara "quarrel," Oscan sverrunei "to the speaker").
Also related to the second element in answer. The secondary sense of "use bad language" (early 15c.) developed from the notion of "invoke sacred names." Swear off "desist as with a vow" is from 1898. Swear in "install in office by administration of an oath" is from 1700 in modern use, echoing Old English.