The centers in the brain which relax your muscles in rem sleep are left "on" while you wake up, causing this phenomenon. This occurs usually due to fragmentation of sleep. Having adequate sleep can be of benefit. If you're having them often, see a sleep doctor so it can be evaluated ; if needed, treated. Hope that helps!