The most obvious explanation comes from a boxer being saved by the round-ending bell.
Alternative: A guard at Windsor Castle in the Victorian times was accused of being asleep on night duty. He vigorously denied this and, in his defence, said that he had heard Big Ben (which could be heard in Windsor in those days before traffic and Heathrow Airport) chime 13 at midnight. The mechanism was checked and it was found that a gear or cog had slipped and that the clock had indeed chimed 13 the previous night - he was truly Saved by the Bell.
Alternative: It came into use as a boxing term in the late 19th century, but had earlier origins from the 17th century. The term described being saved by ringing a bell attached to a coffin to help with the very real problem of people being buried alive (due to lack of medical understanding of unconsciousness, comas, seizures and other death-like states therefore people were erroneously pronounced dead). There were several patents in England and the USA for safety coffins with the bells incorporated into the designs registered in the 19th century and up to as late as 1955. There was even a society to help with this problem, Society for the Recovery of Persons Apparently Dead. The term Dead Ringer is also associated with this idea. Thanks to Teresa Kappers-Wright.