"There is no real mystery about how unicyclists stay upright — they pedal
so as to keep their point of contact with the ground under their center of
gravity.
    But pedaling is confined to the plane of the wheel, and so a sideways
fall has to be countered by first turning the wheel-plane. This may be
done by upper-body rotation, using angular momentum conservation and
wheel/ground friction.
    As a result, a competent rider can control the machine near upright by
continual small adjustments of the wheel-plane plus minor pedaling to and
fro. This may be either static balancing (‘idling’) or a subsidiary component
of steady progress." - Johnson


    It is possible to gain both longitudinal and lateral stability on a unicycle. These depend on the pitch and roll angles. Pitch is the rotation made in the horizontal (x) axis and Roll is the vertical (y axis) rotation. Longitudinal stability is attained by pedaling faster or slower. Pedaling involves your thighs and shanks and gives them a good work out even after a short ride. The two sides of the rider's thighs and shanks are used alternately and not simultaneously. Longitudinal stability is also controlled by the rider moving their torso and arms forward or backward. Lateral stability depends on longitudinal stability. Lateral stability is obtained by going in the direction the rider feels that they are falling in. Unicyclist are constantly correcting themselves in order to stay stable. In order to go in the direction the rider is falling they must lean their torso sideways, countering their shift in weight by pulling in or pushing out their arms and twisting their hips to physically turn the seat. Turning with the hips makes enables rider's to make sharper turns.

    Stability of the pitch and roll angles are needed for the rider to control the speed of the wheel, which is directly related to the Yaw angle (z axis). Neither the pitch or roll angle may exceed 90 degrees for the rider to maintain their stable posture. If a rider cannot maintain their posture on the unicycle for more than one second, they are not in control. Once in control, the rider may chose which direction they would like to go in. A rider must maintain constant control in order to overcome the influence to fall. The rider can never stop moving or else they will lose control. It is possible to maintain control at very low speeds, but that is usually takes lots of skill. A rider's posture is maintained by the centrifugal force created by the rider's movements dynamically. Stability is possible even on uneven terrain. A skilled rider will be able to shift their weight and change their pitch, roll and yaw angles so that they will still be vertical with respect to gravity's pull.

Elements of A Human Riding a Unicycle
Stick Human
Diagram from Sheng

If you want to see 12 pages of mathematical proof of how a human can ride a unicycle click here!