The term used is "spontaneous sobriety" and it happened to me as well. I found the term by googling to see if anybody had the same experience I did.
On the night of April 13th 2017 I was drinking as I did every night and I was planning on doing subsequent nights for the foreseeable future. I gulped the last of my whiskey and wasn't anywhere near where I needed to be because of my astronomical tolerance. It was too late to go to the store and I didn't have any more liquor on me.
In the dark with only the TV providing some light I had a moment of clarity. I told myself I wasn't happy, I didn't want to live like this anymore, and I was finished. Somehow my gut was telling me I wasn't joking this time but that I really meant it.
How it happened to me or anybody else is anybody's guess. I kept hitting new low after new low and was on the express lane to an early grave. I thought I was a lost cause. Then just like that...poof my compulsions were gone.
Good luck on your journey.