The original meaning of this phrase/term was much narrower than today. During WWII ships that got under attack from enemy aircraft recorded a ‘near miss’ for bombs that exploded close enough in the water to cause damage to the hull.
The meaning has since then broadened considerably, meaning any mishap that was narrowly avoided.