have a close call
definition
to narrowly avoid a dangerous or bad situation
example
I had a close call when a car ran a red light—I barely managed to stop in time.
word origin — From American baseball — a 'close call' was a referee's ruling so close to wrong it nearly went the other way.