President Mahmoud Ahmadinejad of Iran has not been having a very good month, which is good news both for the beaten-down people of Iran and for the outside world.

The populist demagogue, it seems, is not so popular with important elements of Iranian society growing uneasy over the price Iran may have to pay for his belligerent pursuit of nuclear technology. This week, Mr. Ahmadinejad’s oil minister acknowledged that foreign banks were pulling back from financing Iranian oil projects because of the worsening nuclear dispute.

The clearest evidence of Mr. Ahmadinejad’s troubles came in last week’s elections for municipal offices and the national council that oversees the work of Iran’s supreme leader, Ayatollah Ali Khamenei. Mr. Ahmadinejad’s supporters fared surprisingly poorly. The main gainers came from two very different opposition groups, one aligned with former President Ali Rafsanjani, an establishment conservative, and the other with remnants of the cautious reform movement led by former President Mohammad Khatami.

Mr. Rafsanjani, a venomous foe of Israel (with his own nuclear appetites), is so notorious for the corruption that marred his presidency that his political career had almost gone into eclipse. Mr. Khatami’s followers are more high-minded, but still managed to fumble Iran’s best chance for reform in decades. What distinguishes them from Mr. Ahmadinejad’s supporters is their recognition that Iran exists in the real world. They understand that its future requires good relations with foreign investors, trade partners and educational institutions.