In the contest of global narratives, China has sought to cast itself as a peaceful nation opposed to dividing the world into rival camps. In contrast, it has accused the United States of building alliances that will drive the world toward a new Cold War.

Yet Russia and North Korea’s mutual defense treaty, which calls for the two countries to provide immediate military assistance to each other in the event of war, is exactly the kind of bloc-building that China has charged the United States with. China’s closest strategic partner and its only treaty ally — Russia and North Korea — are now the ones heightening the risk of Cold War-style confrontation in northeast Asia.

The pact also creates more headaches for Beijing by appearing to deepen the semblance of a trilateral axis between China, Russia and North Korea, which China has sought to avoid. “Beijing has very carefully stayed away from the optics of a China-Russia-North Korea axis,” said Yun Sun, the director of the China program at the Stimson Center in Washington. “It wants to keep its options open.”

Japan, South Korea and the United States could now decide that the threat posed by a Russian and North Korean defense treaty requires them to enhance their own security arrangement, announced last year at Camp David, by increasing troop levels or strengthening defenses along China’s periphery.

For those reasons, China’s top leader, Xi Jinping, might not welcome the budding bromance between President Vladimir V. Putin of Russia and Kim Jong-un, the leader of North Korea. Meeting in Pyongyang on Wednesday, Mr. Putin and Mr. Kim heralded the defense agreement as the beginning of a new era in their relations.