During REM (rapid eye movement) sleep, the brain sends signals that shut off most voluntary muscle activity, a state called atonia. This is mainly driven by neurons in the brainstem that release inhibitory chemicals, which block the signals from the brain's motor areas to the spinal cord motor neurons. It keeps the body still while the brain is busy producing vivid dreams, so you do not act out your dreams.
If this switch misfires, a person can wake up while still paralyzed, which is known as sleep paralysis. Only the eye and breathing muscles, along with the heart, keep working normally during REM.