In common language, the word “hex” is often used synonymously with the words curse or jinx to refer to an unfriendly spell meant to bring about mischief.
The word hex derives from the Germanic word originally meaning witch. Middle High German hecse, hexse “witch”. Modern German hexen means “to cast a spell/charm, to hex” and Pennsylvania Dutch German hexe “to practice witchcraft”. The word is related to the Old High German hagazussa “hag”. The word was not used to refer to a magic spell till the early 20th century.
Completely unrelated: Ancient Greek heks “six” gives us such words as hexagram.