Sleep paralysis happens during the transition into or out of the REM state. Brain signals get crossed, and the body and mind become unsynchronised from the sleep process: the body stays paralysed, but the conscious is now awake.
At this time, the brain kicks into survival gear, becoming oversensitive in this heightened state. The subconscious reads everything around it as a threat causing hallucinations of evil spirits or figures, attached with feelings of fright or dread.
After a few minutes, but what can feel like ages, the paralysis wears off and the body is able to move again.