A story element meant to hint at later story elements in retrospect and/or upon multiple readings.
There are two types of foreshadowing, with a certain amount of overlap.
Diegetic: The characters have some sort of knowledge of upcoming plot developments, and deliberately hint at them. Or they accidentally hint at them. This knowledge can be from time-travel, prophetic visions, non-linear storytelling, or from plain ol' experience. Imagine a hypothetical Dr. Smith with knowledge of a certain device.
Smith: Stop, you fool! If you activate the McGuffin device, you'll kill us all!
Jones: You always were afraid of progress, Doctor!
And then the McGuffin device tears the entire building apart on a subatomic level, killing Smith, Jones, Jones' henchmen, and causing neighbourhood property values to drop like a rock.
It should be noted that out-and-out predictions rarely qualify as foreshadowing, but we shall pretend they do for the sake of these two examples.
Non-Diegetic: The characters have no knowledge of the upcoming events, and the resemblance to or hinting (usually in the form of accidentally prophetic statements) at certain elements in the story's "present" to said later events is entirely metatextual.
Smith: Stop, you fool! If you activate the McGuffin device, you'll kill us all!
Jones: You always were afraid of progress, Doctor!
And then, since someone forgot to carry a one somewhere, the McGuffin device turns Jones into a slavering monster which kills Smith, Jones' henchmen, and then dies itself, causing neighbourhood property values to rise due to increased tourism and, eventually, lucrative book sales.
Smith's statement was correct, but in two different ways. He saw the first one coming, he did not forsee the second one, yet it was correct in the letter, if not the spirit.
The difference between the two forms is that the former can be used to indicate, in retrospect, that the character knew something the audience didn't yet. The latter is effectively just the writer playing at silly buggers.
See also dramatic irony.