So much for handshake diplomacy.

President Obama’s bid to mellow 30 years of hatred and hostility blew up in his face at the United Nations when Iran’s new leader, Hassan Rouhani, snubbed him three times — and wouldn’t even meet him for a much-anticipated grip and grin.

The salvo of diplomatic insults began when Rouhani failed to join Iranian delegates at the General Assembly to hear Obama make an extended overture to Iran in his annual address.

Instead, Rouhani gleefully tweeted that he was “in a meeting with International Monetary Fund Chief Christine Lagarde.”

Then, when Obama hosted a luncheon of world leaders — during which insiders had hinted there might be a historic handshake — the president was left empty-handed after Rouhani, a supposed moderate, didn’t show.

He didn’t even respond to an RSVP, officials said.

Iranian state TV offered a limp excuse: “Iran President Hassan Rouhani has skipped a United Nations lunch banquet because alcohol was served.”

Less than two hours later, two senior administration officials revealed to reporters that Rouhani had refused to even meet for a handshake with Obama.

The president had left himself wide open for a snub in his address to the General Assembly when he proposed direct talks with Tehran.

“The roadblocks may prove to be too great, but I firmly believe the diplomatic path must be tested,” he said.

The president also took the unusual step of admitting that the CIA orchestrated the 1953 coup that ousted Iran’s then-president, Mohammad Mosaddegh. And he expressed outrage over the deaths of “tens of thousands” of Iranians by poison gas during Tehran’s 1980s war against Saddam Hussein’s Iraq.

The snubs heard ’round the world followed weeks of buildup from both sides about renewed openness to diplomacy for the first time since the Iranian revolution in 1979.

The White House said for days that no meeting was scheduled — but at the same time hinted that the two leaders could have a “hallway” summit and symbolic handshake that would mark a diplomatic breakthrough.

Rouhani helped fuel the anticipation in an NBC interview and op-ed piece in The Washington Post in which he suggested his election marked a shift away from antagonism to the West.

But after apparently feverish talks between the two sides, the hopes of even a casual Obama-Rouhani meeting collapsed.

“The Iranians got back to us,” one administration official said in a briefing. “It was clear that it was too complicated for them to do that at this time, given their own dynamic back home.”

During an interview with CNN Tuesday night, Rouhani said he simply did not have enough time to meet with Obama.

Yet Rouhani found time to tweet throughout the day about his meetings with the French and Austrian presidents and the Pakistani prime minister.

Obama later attended a health-care forum with former President Bill Clinton rather than listen to Rouhani make his international debut with a speech that had touches of his predecessor Mahmoud Ahmadinejad’s rhetoric.

And to make sure the world knew, Obama told his Twitter followers to watch him at the Clinton Global Initiative event — which just happened to be at the same time Rouhani was due to make his address to the General Assembly.

“Don’t miss two presidents discussing health care,” Obama tweeted. Half an hour later he tweeted, “Happening now. President Obama and Bill Clinton are discussing health care.”

While Clinton played the role of interviewer, asking Obama about the new Affordable Care law, Rouhani took the UN microphone.

He began with a tone that recalled the anti-US rants of Ahmadinejad, when American delegates and other UN diplomats would routinely walk out.

Rouhani claimed that the United States and its allies were responsible for major crimes, including “the arming of Saddam Hussein with chemical weapons.”

Like Ahmadinejad, he denounced the US-led efforts to hit Iran with economic sanctions. “These sanctions are violent, pure and simple,” Rouhani said.

He struck a more hopeful note when he said Iran was willing to enter negotiations over Tehran’s nuclear program — but insisted that it is designed to produce nuclear power, not weapons.

“We should not just tolerate others. We should rise above mere tolerance and work together,” he said. “This is a unique opportunity. The Islamic Republic of Iran believes that all challenges can be met successfully.”

He added, “I listened carefully to the statement made by President Obama today,” but didn’t indicate what he thought of it.

Instead, he expressed hope that Obama has the political will to “refrain from following the shortsighted interests of warmongering pressure groups [and] we can arrive at a framework to managing our differences.”

Meanwhile, during his interview with CNN, Rouhani departed sharply from his despised predecessor when he called the Holocaust a “reprehensible” crime against humanity.

Ahmadinejad sparked outrage in 2005 when he called the Holocaust a “myth.”

Earlier in the day, Obama made a determined appeal to improve US-Iranian relations in his speech.

Rouhani’s overtures could “offer the basis for a meaningful agreement” to curb Iran’s nuclear program, he told delegates.

Obama mentioned Iran 26 times, many more than he did any other country.

Obama offered another olive branch when he raised the issue of banning chemical weapons and noted that Iran had suffered from Iraqi poison gas.

The ban on such weapons “is strengthened by searing memories of soldiers suffocated in trenches; Jews slaughtered in gas chambers; and Iranians poisoned in the tens of thousands,” he said.

Additional reporting by Larry Celona