The halachah is clear: a man must not leave the synagogue before the chazzan finishes the Amidah, and must not pass a synagogue without entering it to pray. Gaster's Exempla (No. 320, 1924) tells the story of a Jew whose observance of that small rule saved his life.
The man had enemies at court. They had convinced the king, through careful lies, to order his death — but the plot was clever. The king sent him on a harmless-seeming errand to a lime kiln outside the city, having privately instructed the master of the kiln to throw into the furnace the first man to arrive that morning bearing the king's seal.
The Jew set out with the letter. On his way, he passed a synagogue. He remembered the rule — do not walk past a synagogue, enter it — and he stepped inside. The service was already in progress. He stayed to pray. He stayed a long time.
Meanwhile, his chief enemy at court had grown impatient. He wanted to confirm that the Jew was dead. He rode out to the lime kiln himself to check. He arrived ahead of the delayed Jew, bearing no royal letter but demanding information. The master of the kiln, following his orders exactly, grabbed the first man who came demanding news and threw him into the furnace.
The enemy burned in the fire he had prepared for the Jew.
When the Jew finished his prayers and finally arrived, he delivered the letter to an empty shop. He walked home safely. Psalm 7:16 had already written the moral: He digs a pit and scoops it out, and falls into the hole he has made. A synagogue stop, the sages say, is a small thing. Sometimes it is the smallest thing that turns a death sentence into another Tuesday.