How to stop your boat from sinking … (and succeed)

Has it ever happened to you at 2 am, to wake up aboard your sailboat, sailing and resting your feet on the ground feeling wet? I think it is the worst thing you can experience, especially if you are moving...