To challenge the power of his chief rival, the United States, China’s top leader, Xi Jinping, has linked arms with two anti-Western states, declaring a “no limits” partnership with Russia and pledging “unswerving” support for North Korea.

But the specter of a budding bromance between President Vladimir V. Putin of Russia and the North Korean leader, Kim Jong-un, after their meeting this week in eastern Russia, may not be as welcome a development for Mr. Xi as it might initially seem.

Closer ties between Pyongyang and Moscow could result in both countries being less reliant on Beijing. That might diminish China’s perceived clout in global negotiations over ending Russia’s war in Ukraine and curtailing North Korea’s nuclear program.

“I doubt Xi is overjoyed to see the Kim-Putin love-fest unfolding across China’s border,” said John Delury, a professor of Chinese studies at Yonsei University in Seoul. Mr. Kim and Mr. Putin, he said, have reasons to seek more autonomy and leverage from China, the “dominant power in the triangle,” by strengthening their bilateral ties.

Russia could conceivably gain more weaponry from North Korea to intensify its war in Ukraine. North Korea could garner aid or technological assistance from Russia and ramp up its nuclear weapons program.

“All this activity would come on Beijing’s doorstep but outside its control or influence,” Mr. Delury said.

For China, such cooperation may embolden Russia and North Korea to escalate their provocative actions.

That might be a headache for Beijing, which wants to avoid coming under increased pressure to rein in Pyongyang and Moscow. China has also sought to prevent its neighbors from drawing closer to Washington. Mr. Kim’s missile tests have already contributed to the decision last month by South Korea and Japan to put aside their historic differences to sign a trilateral defense agreement with the United States.

Perceptions about China’s handling of North Korea and Russia matter because, perhaps more than at any time in its history, China is bidding for a greater share of global leadership. It believes that its unprecedented economic development over the past four decades, along with its size and military might, gives it the legitimacy to champion an alternative world order in which the United States is no longer the sole dominant superpower.

To underscore that, the Chinese Foreign Ministry on Wednesday issued a sweeping proposal to overhaul global governance by giving more power to developing nations and avoiding “camp-based confrontation,” a reference to what China sees as a U.S.-led effort to split the world into separate blocs reminiscent of the Cold War.

China’s appeal has largely targeted the Global South, as well as countries with grievances toward the West. But to succeed in the long run, Beijing’s goal of reshaping the world order will require broader support, including from U.S. allies around the globe.

On that score, Mr. Xi has had little success. His tacit support for Russia’s invasion and his increasingly aggressive claims to the self-governed island of Taiwan has largely alienated China from the club of Western-led nations in a way unseen since the Tiananmen Square massacre in 1989. China has tried to shift perceptions, at least on Ukraine, by proposing a political settlement and dispatching a peace envoy, but such efforts have been widely dismissed in the West as largely serving Russian interests.

Even now, China must weigh how closely it wants to be seen cooperating with Russia and North Korea. Sergei K. Shoigu, Russia’s defense minister, suggested in July that the three countries conduct joint military drills to counter trilateral cooperation in the region by the United States, South Korea and Japan, according to South Korean lawmakers who were briefed by the South’s National Intelligence Service.

For Beijing, any outward appearance of solidifying an axis of three Western-opposing nations, each with territorial ambitions, may only undermine its interests, said Paul Haenle, a former director for China on the National Security Council in both the George W. Bush and Obama administrations. Such a move would contradict China’s own criticism of “bloc politics,” he said, and raise the risk that U.S. allies would more closely align with Washington and its calls for tougher restrictions on China.

Mr. Haenle was the Bush administration’s representative from 2007 to 2009 in the so-called six-party talks on North Korea’s nuclear disarmament. Back then, he said, China seemed more willing to set aside the differences it had with the United States. The hope was that China would use its influence over Pyongyang, as the North’s only ally and its primary source of trade and economic assistance, to achieve denuclearization of the Korean Peninsula.

Now, North Korea is among a long list of issues like climate change, military-to-military communication and fentanyl that China refuses to address unless the United States makes concessions. Beijing wants Washington to ease restrictions on access to advanced U.S. semiconductor technology and withdraw its support for Taiwan.

“When I was part of the six-party talks, the context was much more about denuclearization with geopolitics in the background,” Mr. Haenle said. “That has flipped around now.”

“China has decided to keep North Korea close for strategic leverage vis-à-vis the U.S.,” he continued.

That makes any erosion of Chinese influence over Pyongyang concerning to Beijing. The symbolism of Mr. Kim visiting Russia, and not China, for his first overseas trip in more than three years is unmistakable. China will also be wary of any technological support that Russia might give North Korea that could bolster Pyongyang’s nuclear weapons program.

“Political and economic cooperation between Russia and North Korea won’t affect China too much, but if military cooperation involves nuclear weapons or nuclear weapons delivery vehicles, it will increase uncertainty in northeast Asia and affect China’s peripheral stability,” said Xiao Bin, a researcher for the Institute of Russian, East European and Central Asian Studies at the Chinese Academy of Social Sciences.

While North Korea is China’s only treaty ally, the relationship has at times been rocky, and not always as close as “lips and teeth,” as was once described by Mao Zedong. Relations chilled in 2017 after China joined United Nations Security Council sanctions aimed at stopping North Korea’s nuclear weapons and ballistic-missile program. Pyongyang lashed out in unusually pointed language, accusing Beijing of “mean behavior” and “dancing to the tune of the U.S.”

Ties between China and North Korea improved the next year after Mr. Kim traveled to Beijing and met Mr. Xi for the first time. China had been nervous about a planned meeting between Mr. Kim and President Donald J. Trump resulting in a grand bargain that would exclude China from future negotiations concerning the Korean Peninsula.

“To the extent there is a strategic objective for China, it is largely to maintain stability. They are not interested in problem-solving,” said Victor D. Cha, a professor of government and international affairs at Georgetown University and the Korea chair at the Center for Strategic and International Studies in Washington. Pyongyang’s mercurial behavior may be an irritant to Beijing, but it is tolerated as long as the regime remains in place, serving as a buffer against U.S. forces stationed in South Korea.

“They want the buffer,” Mr. Cha continued. “They do not support unification, and they just don’t want things to get out hand in Korea.”

Olivia Wang contributed reporting.