Like MAF, I used to have these weird panic / anxiety attack things just before sleep. Like my body would suddenly decide "shit! you're not breathing! Wake up wake up!"... very annoying. But you might want to check into sleep apnea... that has such symptoms, and I might be wrong, but I think it can be dangerous.
The solution for me, funnily enough, was sleeping more. I'd been going through a stressful time at work, and I stayed up late at night just immersing myself in other stuff to make my day feel worthwhile. Once I forced myself to get some rest, the symptoms subsided.
My doctor also explained how you can trick your mind into overbreathing as MAF put it... your lungs are already part full with air, and because you're so self-conscious about it, you ask them to pull for more, but the capacity remaining isn't really enough, which reinforces your self-consciousness about it or makes you panic. Thats possible.