Be saved by the bell

By the skin of one's teeth


Salvarsi in corner

Salvarsi in extremis / Salvarsi per un pelo


Meanings
Fig.: saved from a dangerous or unpleasant situation by a timely intervention of someone or something

Examples
I wasn't ready at all for the math test, when the fire alarm went off and we had to leave the school building. I was definitely saved by the bell!
Non ero pronto per la verifica di matematica, quando improvvisamente è scattato l'allarme antincendio e abbiamo dovuto evacuare la scuola. Salvo per un pelo!

My mother had started giving me the third degree about dating Frank, when our neighbors knocked at the door. I was saved by the bell!
Mia madre stava per farmi il terzo grado sul mio rapporto con Frank, quando i vicini hanno bussato alla porta. Salvata in extremis!

She had promised to take out her great aunt and her eighty-year-old friends for lunch, but she was saved by the bell because her great aunt had a bridge game that she had forgotten about
Aveva promesso alla prozia di portare fuori a pranzo lei e le sue amiche ottantenni, ma è stata salvata in extremis dal fatto che all'ultimo momento la zia si è ricordata di un precedente impegno di bridge

Origin
 Although there is a widespread belief that this expression relates to people who, mistakenly pronounced dead and buried alive, could be saved by ringing a bell attached to the coffin, there's no evidence about it. This idiom, actually, was first used in the second half of the 19th century and it comes from boxing slang: it refers to a boxer who is being severely beaten and is saved from his misery when the bell rings the end of the round