The idea of the apple falling on Newton's head was invented by Isaac Disraeli (father of British Prime Minister Benjamin Disraeli) in the early 19th century, nearly 150 years after the supposed event.
Newton, however, did himself relate the story (toward the end of his life) of his having observed an apple fall, which provided the impetus for his theory of universal* gravitation. As his friend William Stukely related:
"... the notion of gravitation ... was occasion'd by the fall of an apple, as he sat in a contemplative mood. Why should that apple always descend perpendicularly to the ground, thought he to him self. Why should it not go sideways or upwards, but constantly to the earths centre? Assuredly, the reason is, that the earth draws it ... there is a power, like that we here call gravity, which extends itself thro' the universe."
[See Newton's Apple and Other Myths about Science, edited by Ronald L. Numbers]
*Thanks to @jameslarge comment