“With” is originally a shortening of “wither”, cognate with German wider “against” and, further afield, with Sanskrit vitaram “further”, from the Indo-European particle of separation *wi- and the comparative suffix *-tero-.
The semantic development of English “with” is neatly described in the Oxford English Dictionary as follows:
The prevailing senses of this prep[osition] in the earliest periods
are those of opposition (‘against’) and of motion or rest in proximity
(‘towards’, ‘alongside’), which are now current only in certain
traditional collocations or specific applications. These notions
readily pass into fig. uses denoting various kinds of relations, among
which those implying reciprocity are at first prominent. The most
remarkable development in the signification of with consists in its
having taken over in the Middle English period the chief senses
belonging properly to Old English mid mid prep.1 (cognate with Greek
μετά with). These senses are mainly those denoting association,
combination or union, instrumentality or means, and attendant
circumstance. These are all important senses of Old Norse við, to
which fact their currency and ultimate predominance in the English
word are partly due. The last important stage was the extension of
with from the instrument to the agent, in which use it was current for
different periods along with of and through, and later with by, which
finally superseded the other three. The range of meanings in general
has no doubt been enlarged by association with Latin cum. The
interaction of senses and sense-groups has been such that the position
of a particular sense in the order of development is often difficult
to determine.
In other words: the shift in meaning of the English preposition was at least partially influenced by the usage in Old Norse.