It dates from medieval England when households revolved around a fire upon which a pot would be continuously simmering. This was linked to some sort of bell which would chime continuously. If the fire went off, the energy (heat) from the fire would stop the chiming thus causing the alarm. Hence we use the phrase when the alarm goes off! More @Wikipedia
Hover over any link to get a description of the article. Please note that search keywords are sometimes hidden within the full article and don't appear in the description or title.