In mid-November, Iran dispatched a top official to Beirut to urge Hezbollah to accept a cease-fire with Israel. Around the same time, Iran’s U.N. ambassador met with Elon Musk, an overture to President-elect Donald J. Trump’s inner circle. And on Friday, it will hold talks in Geneva with European countries on a range of issues, including its nuclear program.

All this recent diplomacy marks a sharp change in tone from late October, when Iran was preparing to launch a large retaliatory attack on Israel, with a deputy commander of the Islamic Revolutionary Guards Corps warning, “We have never left an aggression unanswered in 40 years.”

Iran’s swing from tough talk to a more conciliatory tone in just a few weeks’ time has its roots in developments at home and abroad.

Five Iranian officials, one of them a Revolutionary Guards member, and two former officials said the decision to recalibrate was prompted by Mr. Trump winning the Nov. 5 election, with concerns about an unpredictable leader who, in his first term, pursued a policy of “maximum pressure” on Iran.

But it was also driven by Israel’s decimation in Lebanon of Hezbollah — the closest and most important of Iran’s militant allies — and by economic crises at home, where the currency has dropped steadily against the dollar and an energy shortage looms as winter approaches.