When you spin your head around in circles, the world appears to continue to spin.
- Why do one's surroundings still seem to rotate when you stop whirling around in a circle?
- What is happening in the brain?
On each side of your head, in the middle ear, there is a system of canals in which displacement of a group of hair cells measure the movement along the 3 axes (the canals are tilted a bit back from 90°, so the coordinate system is not identical with that of the head).
So, when you move your head around and around as your body "whirls", the cupula of the horizontal canal (HC), which encases the hair cells, moves in the opposite direction and displaces the hair cells, causing the firing of action potentials. Once your head stops, the viscosity of the fluid in which the cupula is suspended prevents it from snapping right back to it's "default" position, so action potentials continue to be fired, and your nervous system (falsely) senses that your head is still moving.
Courtesy of Scholarpedia Vestibular System
You can find similar aftereffects when you stare out the front window of a moving vehicle for a couple of minutes and then stop: the landscape suddenly seems to slowly move away from you for some time; or when you stare out the widow of a train: when it stops the landscape appears to slowly move in the opposite direction. Aftereffects of this type can have any direction: when you stare at a rotating image and the rotation stops, the image appears to rotate in the opposite direction. Depending on the stimulus, this can be a smooth motion or it "jumps" forward and back.
This is called the direction aftereffect (DAE), "whereby prolonged exposure to a moving pattern affects the perceived direction of subsequent motion" (Clifford, 2002). This is an effect of perceptual adaptation, where the brain compensates for a supposed error in perception.
The mechanism behind this phenomenon was tested by Schrater and Simoncelli (1998):
@ChuckSherrington is correct except for a few very minor errors/simplifications.
First, the three semicircular canals that form the Vestibular (or balance) System are located in a safe little pocket of bone called the inner ear. The three canals are oriented at (basically) 90° angles to each other so that we can maintain our balance no matter which position our head is in (e.g. hanging from monkey bars upside down does not make young people dizzy, nor does it change their sensation of gravity.*) Finally, and crucially, they are linked with our ocular system through a neuronal connection called the vestibolo-occular reflex (VOR). Because the connections are excitatory, increased firing from a canal afferent leads to contralateral movement of the eyes (which is how spinning ice skaters can keep track of / focus on where they are visually). I will not elaborate on the role of the vestibulocollic reflex (VCR) in the stabilization of visual acuity for brevity's sake. Normally all this occurs without notice.
The latency of action of the rotational vestibuloocular reflex (r-VOR) is 7-15 milliseconds, which is the time required for the eyes to respond in an equal, but opposite, manner to the motion of the head. This time is remarkably fast compared with the latency for visually mediated eye movements, which is longer than 75 milliseconds.
What happens is that with spinning (say, in one plane), the cilia of the hair cells (see @Chuck Sherrington's diagram) are displaced, and remain displaced as long as one is spinning with the same velocity and direction. Once the spinning suddenly stops, the cilia proceed to move to their default position, tricking the VOC into moving the eyes in the opposite direction repeatedly until the cilia come to a complete stop. You can observe this phenomenon by looking into the person's eyes immediately after they stop spinning (make sure they are safe from falling.) Once things settle down in the inner ear, the vertigo (perception of spinning) stops shortly thereafter as well.
The perception described by @what is different altogether.
 Anatomy and Physiology of the Vestibular System Gizzi, et. al.
*I say young people because some decreased sensitivity to semicircular canal fluid movement occurs as we age, and elderly people may, indeed, become dizzy with drastic changes in position. This decreased sensitivity is often a contributing factor to falls in the elderly.