perhaps abstracted from Old English swa same "the same as," but more likely from Old Norse same, samr "same," both from Proto-Germanic *samaz "same" (source also of Old Saxon, Old High German, Gothic sama, Old High German samant, German samt "together, with," Gothic samana "together," Dutch zamelen "to collect," German zusammen "together"), from PIE *samos "same," from suffixed form of root *sem- (1) "one; as one, together with."
Old English had lost the pure form of the word; the modern word replaced synonymous ilk. As a pronoun from c. 1300. Colloquial phrase same here as an exclamation of agreement is from 1895. Same difference curious way to say "equal," is attested from 1945.