Enter All-Wheel-Drive. There are websites that will go into great detail about how AWD works, how it differs from 4-Wheel-Drive, and how automakers go about making AWD systems.
Let's say you are driving in the mud, and one set of wheels loses traction with the mud. The other set still has traction, moving or trying to move the vehicle. The wheels that lost traction begin spinning. Energy is still being transferred to the wheels, but without traction, the wheels don't move the vehicle. They just spin.
Suffice to say, the AWD distributes energy to whichever (front or rear) set of wheels is not spinning. In other words, while driving, if one set of wheels spins, the energy that would otherwise be put into moving the vehicle with those wheels is transferred to the wheels that aren't spinning - the ones actually moving the vehicle.
As those wheels move the vehicle, the other wheels eventually rotate when they have traction with the ground. The now-rotating wheels begin to accept energy from the transmission. The amount of energy transferred, to the wheels with traction, is proportional to the amount of slipping of the other wheels.
The specifics of the AWD system, the transmission, and the surface that the vehicle is on affect the slipping of the wheels, the energy transfer back-and-forth to the sets of wheels, and the overall motion of the vehicle. This results in a continuously unpredictable affair.
You can still get out of the mud.
If you read and understand above, congratulations. You deserve to watch a video.