I've written about this before, so I'm just gonna to reuse the material that I've used before.
What you've described sounds like Sleep Paralysis--a phenomenon in which people, either when falling asleep or waking, temporarily experience a sense of inability to move. Sleep paralysis usually strikes panic and is often accompanied by hallucinations. These hallucinations can be violent. Some people even hallucinate about sexual assault, which they've attributed to demons. No doubt they feel very real.
Here are a few ways to help you wake up from sleep paralysis
1. Don't Fight
If you feel like you are being held down and you can't move, do not fight back. This will intensify the experience. Not only is fighting back likely to increase the feelings of being held down (so much that it may seem like you are being crushed), but fighting back will also increase the fear, triggering emotional centers of the brain and strengthening this lucid nightmare. Controlling fear is the most important part during these moments. Instead, try to relax and tell yourself, "This is a sleep paralysis, it is temporary, it will pass and I am okay."
2. Feeling pressure on your chest?
Don't push against it. If you feel like a pressure on your chest is pushing you into the bed, relax and mentally pull in the direction in which you're being pushed. What happens is that you eventually "pop" into a full-on dream, or even wake up.
3. Small movements
Wiggle your toe, finger, clench your feet. Most of the feelings of paralysis are in the trunk of your body. So focus. In many cases, this will break the paralysis.
4. Focus on your Breath
An easy way to stop these nightmares is to do some controlled breathing. Controlled breathing does several things at once. For starters, it lessens the feelings of chest pain that sometimes accompany sleep paralysis. Breathing is autonomic like the heart's beating or digestion, so it's not paralyzed like the big muscles in our arms, chest and legs. But breath can be controlled with attention or be affected by severe fear, which may be why sleep paralysis sufferers forget to breathe when under attack. If you can control your breath, you can control your fear. Simply draw your breath in at a normal rate, and exhale fully, using all of your lung capacity. Notice that you can breathe fully without obstruction. This technique will keep you calm as the sleep paralysis runs its course. A few moments of focused breathing with a strong intention to wake up is effective.
5. Think of someone or something that calms you down
Thinking of someone or something you associate with peace, love and safety. This could be Jesus, the Dali Lama, Archangel Michael, a poem, a song, a candle flame, a prayer or even someone you know personally, like your grandmother. This will help you relax.
Like breathing, coughing can be autonomic or consciously regulated. By coughing on purpose, you can jar yourself awake.
7. Make faces
When you realize you are in sleep paralysis, scrunch up your face. In other words, make a face like you just smelled something bad. Snarl and squint. Do this two or three times in a row and the paralysis will break. This is apparently full proof.
8. When you wake up
After you wake up, get out of bed immediately and turn on a light. Wash your face with cold water and have a glass of milk. If you just stay in bed, the chance of sliding right back into sleep paralysis is pretty high.
Do some research on sleep paralysis. The more you know about it, the better you will be at dealing it, even in your sleep.