Close shave
A close or near shave is a narrow escape from some calamity or other, deriving from shave as in a slight or passing touch. This meaning and usage of shave dates from the early 19th century and has nothing to do with shave as in shaving with a razor.