It is not just a rich/poor divide or a rural/urban or a young/old, but a combination of factors at play. While I see little likelihood of a change in the election results, I will be curious to see if the violence forces any internal changes of policy. It is not enough to say "line the urban middle class against the wall and have them shot as counter revolutionary swine." There are a heck of a lot of them, and they are demonstrating an ability to organize and protest in a way that should give any regime in a complex society pause.
The situation bears some similarity to what happened in China 20 years ago. There, the government followed up its crackdown with efforts to woo young technocrats and urban elites who had been in the vanguard of the "Democracy revolution" with the promise of economic opportunities as well as the threat of repression. the bargain was straightforward in China -- forget the forms of democratic freedom, leave the old men in political power, and focus on getting rich and the substance of the Western lifestyle without the political freedoms. It worked fairly effectively.
Ahmadinejad has led the sort of socially conservative/economic populist/nationalist platform that has driven a number of Southern politicians in the past -- most recently Mike Huckabee. It would be a mistake to conclude that it has no real support. But it is equally clear that it is a vision that a substantial number of Iranians (especially young, urban, educated Iranians) do not share. Once the dust settles, the ruling party will need to determine whether it wishes to follow the path of repression, risking further backlash and alienation even of its supporters, or finding some accommodation with a sufficient number of disaffected elements to give them a stake in stability -- aware that this route must result in some ideological or political compromise.