Afterimages are visual phenomena in which some part of an image persists in our vision after the actual stimulus is gone. In simpler words, we continue to see something that is not there anymore. Another term for it is persistence of vision. When the afterimages are strong and persistent enough to interfer with normal sight and be considered a medical problem, they are called palinopsia.
There are negative afterimages and positive afterimages. The positive afterimage has the same coloration as the original image, like a positive color photograph. If you happen to be staring at a the flashbulb of a camera as it goes off, the intense white image that remains even when you close your eyes or look away is a positive afterimage. Positive afterimages are usually very brief and often not even noticed, but the duration depends on the strength of the light and the length of exposure. Positive afterimages are caused by the slowness of the light-detecting chemical reactions in the cells of the retina (see rhodopsin). The result of the hysteresis in that reaction is that the effect of the light stimulation lingers briefly (or not so briefly) after the stimulus has been removed. We are lucky that it works this way, because the fleeting afterimage creates the illusion of smooth and continuous motion when we watch movies, which are just still images presented in very quick succession.
A negative afterimage is like a negative color photograph, where the complementary colors are reversed so that red becomes green and green becomes red, blue becomes yellow and yellow becomes blue, black becomes white, and white becomes black. In the flashbulb example, the positive afterimage of a white spot will be quickly or less quickly replaced by a negative afterimage of a black spot of exactly the same shape. The negative afterimage usually persists longer than the fleeting positive afterimage, but it also depends on the intensity and length of the stimulus.
The explanation for negative afterimages is somewhat complex, but the simplest and most direct factor is a desensitization of the cells of the retina. What makes those cells sensitive to light is a chemical called rhodopsin. A cell's supply of rhodopsin is gradually depleted by chemical reaction during exposure to light. The brighter the light, the faster the chemical is used up. So if a certain part of your retina is exposed to bright light, by staring at a white disk on a black background for example, that part of the retina will become less sensitive to light. If you then move your gaze to a white surface, you will see a negative afterimage in the form of a relatively dark disk. That happens because the cells within the disk image on the retina are now less sensitive to light than those outside the disk image, and so they don't respond as well to the same level of light and you see the relatively dark disk shape, even though the white background is actually uniform in brightness (luminance).
If you stare at a red spot, however, you will see a greenish negative afterimage against the white background. This reversed color effect comes from a desensitization of the cone cells that sense particular colors. Exposure to red light desensitizes the cells that detect that color, but it doesn't affect the cells that are sensitive to green so much. There is more to it than that, however. There are strong neurological mechanisms at work in negative afterimages as well. Humans have three kinds of cone cells, each sensitive to light of one color (red, green or blue), but the story does not end there. The output of those cone cells enters a layer of neural processing in the retina that results in what is called color opponency. The output of that processing is information about color differences, specifically about red vs. green and blue vs. yellow. Because of that processing, a desensitization of red cones will result in a stronger green signal being sent to the brain. Thus a red stimulus produces a green afterimage. A nice illustration of the complementary color effect in an afterimage is the old American flag illusion, where you stare an image of Old Glory in reversed colors for a while and then look at white surface to see the image in normal color.
Afterimages can also be caused by drugs or by damage to nerves in the optical pathway or certain areas of the brain. For most of us, most of the time, afterimagery is very important to normal vision.