President Barack Obama shook hands with Cuban President Raul Castro on Tuesday as both leaders attended an emotional memorial for the late Nelson Mandela. The moment drew fire from key Republicans, including Sen. John McCain, who likened it to shaking hands with Hitler.

The fleeting exchange, captured in photographs and video from a giant soccer stadium in Johannesburg, came after Obama bounded up the steps toward the podium to address the massive crowd.

The United States and Cuba have seen their enmity outlive the Cold War that spawned it — even as Raul’s brother Fidel Castro, now in reportedly poor health, outlasted the decadeslong American embargo meant to push him from power.

The two countries have not had formal diplomatic relations since shortly after Fidel Castro led a 1959 revolution and aligned his country with the Soviet Union. Fidel passed the reins to Raul in 2008.

It was believed to be the first such encounter between the leaders of the two countries since Bill Clinton gripped Fidel Castro’s hand in 2000 at a United Nations lunch.

Shortly after the handshake, Obama delivered a speech honoring Mandela, also called Madiba, in which he seemed to take aim at governments like Castro's, saying: "There are too many leaders who claim solidarity with Madiba’s struggle for freedom, but do not tolerate dissent from their own people."

While this White House has at times signaled a willingness to ease tensions with Cuba, there were no signs of a fresh diplomatic push on anything approaching the scale of outreach towards Iran, which got a boost from a historic Sept. 27 phone call between Obama and Iranian President Hassan Rouhani.

"This wasn't a preplanned encounter," an Obama aide told Yahoo News on condition of anonymity. "Above all else, today is about honoring Nelson Mandela, and that was the president's singular focus."

Still, "as the president said, we urge leaders to honor Mandela's struggle for freedom by upholding the basic human rights of their people," the official said.

Story continues

At a fundraiser for Senate Democrats in Florida last month, Obama sounded optimistic about political change spreading in Cuba and said it was time to “update our policies” — a clear reference to the economic embargo first imposed by then-President Dwight Eisenhower and regularly toughened since.

“Now, I think we all understand that, ultimately, freedom in Cuba will come because of extraordinary activists and the incredible courage of folks like we see here today,” he said. "But the United States can help, and we have to be creative,” Obama added. “The notion that the same policies that we put in place in 1961 would somehow still be as effective ... today in the age of the Internet and Google and world travel doesn't make sense.”

The handshake drew sharp GOP criticism. McCain told Public Radio International reporter Todd Zwillich that it gave Castro a propaganda victory and that Obama shouldn't have done it, noting that American international aid worker Alan Gross has languished in a Cuban cell since December 2009.

"Why should you shake hands with somebody who's keeping Americans in prison," McCain said, adding: "Neville Chamberlain shook hands with Hitler." That was a reference to the British prime minister who wrongly believed he could appease the Nazi leader.

Obama and Castro had exchanged a few words before the American president moved on to share a handshake with Brazilian President Dilma Rousseff and kiss her on both cheeks. Rousseff has angrily condemned U.S. spying in her country, which reportedly included her own communications.

And Obama also briefly exchanged greetings with Afghan President Hamid Karzai, with whom he also has been at odds recently.