"Run amok" sounds like an old English idiom about mud. It is actually a Malay word, carried to English by Portuguese travelers.
The source is Malay amuk, "attacking furiously" or "rushing in a frenzy." Wikipedia links it to the Malay verb meng-âmuk, "to make a furious and desperate charge." It traces the root further back, to a Proto-Malayo-Polynesian hamuk, "attack."
The first Europeans to write about it were Portuguese. Around 1513 Tomé Pires described Javanese amocos, men who had resolved to die. Duarte Barbosa described Javanese men in Malacca who, after recovering from a serious illness, attacked people with daggers. They would "go like mad dogs, killing until they are killed." Wikipedia dates his account to 1514, and Mental Floss to 1516.
English borrowed the word from Portuguese amouco in the mid-1600s. According to the Oxford dictionary text on Encyclopedia.com, it was first a noun for a Malay man in a homicidal frenzy. The adverb, as in "run amok," dates from the late 1600s.
Captain James Cook helped spread the phrase. Wikipedia says he met amok firsthand in 1770, in frenzied attacks on villagers and animals. Mental Floss dates his written account to 1772, which begins: "To run amock is to get drunk with opium."
Medicine then took the word over. Amok was classified as a psychiatric condition in 1849. Later it became one of the "culture-bound syndromes" in the DSM-IV-TR, a label the DSM-5 dropped. Wikipedia notes that it is increasingly seen as a general pattern of violent behavior, not one confined to Malaysia and Indonesia.
Other cultures had their own names for something similar. In 1876 José Malcampo, the Spanish governor-general of the Philippines, coined juramentado for attackers among the Moro people of Mindanao. Wikipedia also compares the Scandinavian berserker.
One popular story is false. Mental Floss notes that the idea of sailors running ships "a-muck" onto mud banks is a folk etymology. The real word came from Malay, by way of a frenzy, not a swamp.
In everyday English the meaning has softened. Today things that "run amok" are usually just out of control.