The Alarm Went Off:

A friend of mine asked me about this -- why do we say "the alarm went off" when the alarm, or at least the sound, goes on?

I infer that this is related to a gun or a bomb going off, that when something is ready to go it is somehow seen as "on," and then when the trigger turns that readiness into actual firing or detonation the device is seen as "going off." But can anyone tell me more precisely how the phrases came to be this way?