Dodge the/a bullet
Example
“Wow – I dodged the bullet! This morning, half my department was laid off. I’m one of the lucky ones. My job is safe, at least for now.”
Possible German translations of “dodge a bullet”:
Schwein gehabt, nochmal Glück gehabt, mit einem Schrecken davongekommen