At a memorial for former South African president Nelson Mandela, President Obama greeted world leaders, including Cuban President Raul Castro. (Thomas LeGro/The Washington Post)

Sen. John McCain (R-Ariz.) criticized President Obama for shaking the hand of Cuban leader Raul Castro at the memorial ceremony for former South African president Nelson Mandela, comparing the gesture to Neville Chamberlain's handshake with Adolf Hitler at the start of World War II.

"It gives Raul some propaganda to continue to prop up his dictatorial, brutal regime, that's all," McCain said sarcastically. McCain's comments can be heard in an audio clip recorded by Todd Zwillich of The Takeaway radio program.

On his way to the podium, Obama walked down the line of dignitaries, greeting other leaders there to pay their respects. Obama neither made a special effort to shake Castro’s hand nor to avoid him.

But McCain said Obama should not have extended his hand to Castro.

"Of course not," the senator said when asked. "Why should you shake hands with somebody who's keeping Americans in prison? I mean, what's the point?"

That's when he added the Hitler comparison.

"Neville Chamberlain shook hands with Hitler," he said, referring to the British prime minister's infamous handshake with the German dictator as Britain was negotiating Germany’s takeover of the Sudentenland. The agreement paved the way for the spread of Germany's military across Europe.

In contrast, Sen. Marco Rubio (R-Fla.) earlier Tuesday declined to criticize the handshake, instead saying that Obama should have taken the opportunity to press Castro on human-rights issues. (Rubio is Cuban American.)

In his remarks, Obama didn't address Cuba or Castro directly, but he did make reference to leaders who don't respect human rights -- words that could be read as implicitly addressing the Castro regime.

"There are too many leaders who claim solidarity with Madiba’s struggle for freedom, but do not tolerate dissent from their own people," Obama said.

Obama, though, isn't the first U.S. president to shake a Castro's hand. Bill Clinton shook Raul's brother, Fidel's, hand at the United Nations in 2000.

Update 3:44 p.m.: Sen. Pat Leahy (D-Vt.) responds to the criticism of Obama: