Billy: Wow, that was close. Just when I thought the cops would see us, they got distracted by the sound of the bell on Margo’s cat’s collar.
Tom: Yeah, we were saved by the bell. Literally.
The idiom saved by the bell expresses the idea that someone or something is rescued from a dire outcome by a timely occurrence, generally speaking, at the last possible moment, i.e., in the nick of time. A close shave.