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.) probably developed from the notion of "invoke sacred names." Swear off "desist as with a vow" is from 1898. Swear in "install (someone) in office by administration of an oath" is attested from 1700 in modern use, echoing Old English.
[Swearing and cursing] are entirely different things : the first is invoking the witness of a Spirit to an assertion you wish to make ; the second is invoking the assistance of a Spirit, in a mischief you wish to inflict. When ill-educated and ill-tempered people clamorously confuse the two invocations, they are not, in reality, either cursing or swearing ; but merely vomiting empty words indecently. True swearing and cursing must always be distinct and solemn .... [Ruskin, "Fors Clavigera"]