Dreams are controlled by a part of the brain called the cerebral cortex. During REM sleep, signals sent from another part of the brain, the pons, are relayed through the thalamus to the cerebral cortex, and it is the cerebral cortex's attempts to make sense of these signals that causes dreaming.
The pons also sends signals to neurons in the spinal cord, shutting them down and causing temporary paralysis to the arms and legs. This prevents the dreamer from physically acting out his dream and injuring himself. A condition called REM sleep behavior disorder exists, where the pons fails to paralyze the limbs during REM sleep.