WASHINGTON — Over porterhouse steak and cherry pie at a desert estate in California earlier this month, President Obama delivered a stern lecture to President Xi Jinping about China’s disputes with its neighbors. If it is going to be a rising power, he scolded, it needs to behave like one.

The next morning, Mr. Xi punched back, accusing the United States of the same computer hacking tactics it attributed to China. It was, Mr. Obama acknowledged, “a very blunt conversation.”

Ten days later, in Northern Ireland, Mr. Obama had another tough meeting with a prickly leader, President Vladimir V. Putin of Russia. At odds with him over the Syrian civil war, Mr. Obama tried to lighten the mood by joking about how age was depleting their athletic skills. Mr. Putin, a decade older and fending off questions at home about his health, seemed sensitive on the point. “The president just wants to get me to relax,” he said with a taut smile.

While tangling with the leaders of two cold war antagonists of the United States is nothing new, the two bruising encounters in such a short span underscore a hard reality for Mr. Obama as he heads deeper into a second term that may come to be dominated by foreign policy: his main counterparts on the world stage are not his friends, and they make little attempt to cloak their disagreements in diplomatic niceties.