While I'm fairly certain the election was rigged (AFAIK the majority of Iranians, especially young Iranians, are very liberal-minded), it was a clear middle finger from the mullahs to the rest of the world, specifically Israel.
If I'm not mistaken, his leftist economic policies were very popular among the poor. His nationalist rhetoric also struck a chord, given that the United States is occupying the country next door. Actually, I've seen it suggested that his reformist opponent would have won if not for the invasion of Iraq.