You didn't wake up before the alarm went off. What happens is your mind is dreaming about a minutes worth of some random scenario. At the moment the alarm sounds, this scenario undergoes an alternation to incorporate the alarm into the dream and is then stored in your short-term memory. When you fully wake-up, your mind replays the dream, the last bit of which contains the sequence of you waking-up just before the alarm going off.
I used to dream I was waking up, dream I was doing stuff more or less normally, and then things would get really weird and I would semi-lucidly conclude I must be still dreaming, and force my eyes open to wake up again. On occasion it happened repeatedly. And in retrospect, it was obvious that when I was dreaming, my ability to tell I was dreaming was impaired. But then I worried, what if I think I'm dreaming and I'm not?