Ebrahim Noroozi / AP Escorted by bodyguards, Iranian President Mahmoud Ahmadinejad waves to well-wishers as he attends an annual nationwide pro-Palestinian rally marking al-Quds Day in Tehran on Aug. 2, 2013

Shortly after Mahmoud Ahmadinejad took office as Iran’s President eight memorable years ago, a walk-up window appeared in the face of a building just off a leafy square in eastern Tehran. “President’s Public Relations Office,” the sign read, but the window functioned more as a kind of post office. Five days a week, from 8 a.m. to 5:30 p.m. the clerk stationed there accepted letters from ordinary Iranians who traveled for hours, sometimes days, to deposit their requests to the first Iranian President who bore a resemblance to themselves.

This is not as scary as it might sound. Iranian political culture had been the playground of Persia’s elites for more than a millennium, and for all the egalitarian slogans of the 1979 revolution, remained so in the Islamic Republic; a chapter title in one of the better books about modern Iran was telling: “The Mullah Wore Beautiful Shoes.” So was the shorthand for a businessman with connections: “the son of a cleric.” In that context, it becomes easier to grasp the profound early populist appeal of the banty pol who leaves office on Saturday.

Ahmadinejad lived in the modest townhouse he grew up in, right around the corner from the walk-up window. He wore a zippered jacket to work. Everything about him — including the taunts of moneyed north Tehran swells that he needed a bath — suggested that this was a man who understood the concerns of workaday citizens, who were nonetheless gratified when he asked them to write down their specific needs and bring them by in person.

Seven out of 10, according to the man in the window, asked for money.

Mind you this was back when Iran was still flush, years before the sanctions on oil sales and international banking transactions crippled the economy and sent the rial reeling. But even when it was still awash in petrodollars, the Islamic Republic had been a fiscal basket case, a command economy (80% of which is directly controlled by the state) dependent on petroleum sales for the hard currency it then used to import gasoline. Every Iranian knew that Turkey, the next-door neighbor with the same number of people and a fraction of the natural blessings, had become an economic titan during the 30 years Iran ran in place. What Iran led the world in, according to U.N. figures, was opium addiction. When Tehran wanted to raise the quality of life, it began providing hot lunches to civil servants, who dutifully wrapped up the plates of rice and carried them home to the family as dinner.

Nuclear power, Israel … all the preoccupations that formed the West’s views on Ahmadinejad barely registered as controversies inside Iran. By the time the new President put out his call for epistles, he had already called the Holocaust a myth and been quoted saying Israel should be “wiped off the map.” He might not have actually uttered the phrase — it’s entirely possible it was a mistranslation of a less vivid saying (that Israel will disappear amid “the sands of time”) — but the point is he never denied the quote, so pleased was he by the uproar that surrounded him like a force field. He was entirely comfortable standing at the center of controversy, smiling his smug smile.

So it was that Ahmadinejad returned Iran to the role many Americans, at least, found familiar and even comfortable: archvillain. After his 2005 election, there was a flurry of reports that Iran’s new President had been among the students who took over the U.S. embassy in 1979, precipitating the hostage crisis that still defines the relationship three decades later. The reports were not true, but the newcomer’s abrupt arrival on the international scene — out of nowhere — was embraced as helpful and clarifying by those not entirely sure what to make of his predecessor, the librarian Mohammed Khatami, a reformist President who spoke not of the Great Satan but of a “dialogue between civilizations.” Where’s the fun in that?

Politically, Ahmadinejad truly was a product of the fringe. I first saw him at Friday prayers on the campus of Tehran University, campaigning in the center of a small cluster of the Basij, a nationalist irregular militia, and other regime loyalists who showed up there each week. He had been mayor of Tehran for two years yet registered so feebly in the presidential electoral reckoning that a week before election day the leading reformist daily did not even include him in its candidate roundup. But he was catching fire below the radar, his campaign posters done in austere black and white, and prime-time campaign video a truly moving portrait of a man who savored contact with common people.

“I saw him on television,” a shopkeeper named Jafar Shalde told me later, in a Caspian Sea town called Shaft. “I just looked at him and saw he was just like us. So I told everybody I knew — for example, my kids — I told them to vote for him.”

He didn’t travel very well, though. When Ahmadinejad went to New York City each year for the U.N. General Assembly, U.S. journalists lined up to engage him in interviews. Most came away befuddled, unable to square his supremely confident manner with a frame of reference so far from their own reality. Iranians know regime hard-liners talk mostly to one another, reinforcing their own peculiar worldview, which outsiders can take or leave. But as Iran’s nuclear program became one of the world’s major preoccupations, his insistence on his own reality aggravated the situation.

It was always true that, as President, Ahmadinejad had almost no power over the nuclear program, which remains under the direct control of Supreme Leader Ayatullah Ali Khamenei, the unelected cleric who holds ultimate power in Iran. But Ahmadinejad was entirely appropriate as its spokesman. His was the face of Iran’s lurch to the right. The jackboot suppression of the Green Movement four years ago was carried out on his behalf, to assure the re-election of a candidate — a veteran of both the Basij and the Revolutionary Guard Corps, a man of the people who visited a different province every second week, always setting out oversize boxes to collect all those letters (200,000 poured in at the poorest province of them all) — Khamenei must have thought almost too good to be true.

Turns out he was. In his second term, Ahmadinejad broke with the Supreme Leader, challenging the dominance of conservative clerics while building a cadre of his own. The infighting went on for years, and if it was at times entertaining — at one point involving allegations of sorcery — it was because it was playing out on the far-right fringe of the political spectrum where Iranian politics had been allowed to drift.

By then, the U.S.-led sanctions were in place, and with its banking system frozen Iran was bartering tea from India in exchange for oil. The economy that Ahmadinejad had promised to make responsive to working women and men — “to put oil money on the sofre” or dining cloth — was a shambles. And guess who got the blame? The June election was won in a single round by the candidate who most emphasized the need to end Iran’s isolation, and on Saturday, Ahmadinejad will attend the inauguration of Hassan Rouhani, a man who is everything the departing incumbent is not: a cleric, worldly, educated abroad, fluent in English and long a fixture of Iran’s ruling elite.

Rouhani tweets: “Talking impudently against the enemy is not the solution.” And: “The country is now encountered with a 42% inflation as well as unemployment. #Rouhani” Who has time for a letter anymore?