I like this word. It is easy to imagine how it came about, easy to visualise people shouting it out, the rush and confusion, the warnings that led to its eventual meaning.
So where does it come from? Well, it is not a difficult word to trace. It comes into English, through Middle English, from Old French alarme, which in turn came from Italian. You might think that it doesn’t look very Italian in its current form, but it was originally all’arme, which meant “to arms!” It would have been shouted out in warning, or to rouse the soldiers to prepare. Gradually, of course, it lost its sense of weaponry and kept the idea of warning and rousing, which of course extended to waking.
Taking it one step further, all’arme came from the Latin preposition ad, “to”, plus the definite article; arme from Latin arma, which meant “weapon”. From weapon to warning seems to me a logical step.