There is no such thing as a free election in the Islamic Republic. The religious regime seeks the legitimacy of democracy but not the idea of subordinating leadership to popular will. The supreme leader and the Guardian Council carefully monitor campaigns and massage the process. This year, as you mention, Matt, the Guardian Council eliminated more than 99% of the candidates who sought to run for president. It is easy to falsify the results at any stage: The Iranian government forbids independent monitoring. In the 2005 election, Mohammad Bagher Ghalibaf, who led exit polling, claimed fraud after he went to sleep in first place and woke up in third.
You imply that Western analysts underestimate incumbent Ahmadinejad, and I agree. Western journalists and academics hang out in the bookstores around Tehran University and the cafes of northern Tehran where Iranians embrace the reformist tendencies voiced by Mousavi. But, in the projects of western Tehran and the slums of the south, Ahmadinejad's demagoguery is attractive. Many Iranians resent both the fabulous wealth accumulated by the Islamic Republic's elite and their nepotism. This is why, in the last days of the campaign, Ahmadinejad made former President Ali Akbar Hashemi Rafsanjani (perhaps the richest man in Iran) and his extended family the target of his attacks. Iranians juxtapose Rafsanjani's luxuries with Ahmadinejad's ascetic lifestyle. Finally, while the campaign officially was just three weeks long, Ahmadinejad campaigned for four years, spending more time in provincial towns and villages than any of his predecessors.
That said, the numbers don't pass the smell test. The Interior Ministry reported turnout greater than 99% in some provinces. While such numbers are unlikely, both consensus inside Iran and anecdotal accounts from election day suggest that high turnout would benefit Mousavi. As you said, Matt, it seems strange that Ahmadinejad would beat Mousavi in east Azerbaijan (even though Mousavi squeaked by in west Azerbaijan). Or that Ahmadinejad would win former President Mohammad Khatami's home province of Yazd after Khatami campaigned so heavily for the challenger.
Matt, you put your finger on the right question: Why would Supreme Leader Khamenei show his hand like this? Let me take a crack at that.
Remember, in the Islamic Republic, sovereignty comes from God; it doesn't matter what the majority of people think. Khamenei became supreme leader after Ayatollah Ruhollah Khomeini's death in 1989. Khamenei was a compromise candidate. He didn't have Khomeini's charisma or religious credentials. Khamenei ruled by balancing factions. Whenever any politician would get too powerful, Khamenei would cut that person down to size. It hasn't always worked. In 1997, reformer Khatami won a surprise victory against the supreme leader's favorite candidate. Khamenei later regretted letting the results stand after Khatami unleashed passions that threatened regime stability. Indeed, next month marks the 10th anniversary of the student uprising in 1999, which I witnessed firsthand in Iran. When the Guardian Council approved the soft-spoken Mousavi's candidacy, no one expected his message to resonate. But when it caught on, Khamenei decided to nip the problem in the bud. The next couple days will show whether he was successful.