China’s top leader, Xi Jinping, has rolled out the red carpet for President Luiz Inácio Lula da Silva of Brazil, lauding him as “an old friend of the Chinese people.” He has sipped tea in a garden with President Emmanuel Macron of France, treating him to a performance of an ancient Chinese zither. And he has talked on the phone with Crown Prince Mohammed bin Salman, Saudi Arabia’s de facto ruler, offering well wishes for the Muslim holy month of Ramadan.

But even as Mr. Xi has offered a glad hand to those and other world leaders in recent weeks, it has been only the cold shoulder for the United States. China has rebuffed attempts by the Biden administration to restart high-level talks and lower tensions over Taiwan. And Mr. Xi’s government has intensified a campaign of ridicule and criticism of the United States and Western democracy.

Taken together, the efforts to shore up ties with American allies while publicly discrediting the United States reflect Beijing’s hardening position as relations sink to their lowest point in decades over what Mr. Xi has described as Washington’s “containment, encirclement and suppression of China.”

The two-pronged approach, some analysts say, is compelling evidence that Mr. Xi has fully committed to the view that engagement between China and the United States is fruitless, at least for now. And it has lent urgency to concerns that the two powers are on a collision course that could lead to dangerous accidents, or even war, over Taiwan and other geopolitical flash points.

Mr. Xi’s diplomatic effort was rebuffed by the United States and some of its closest allies this week, when a meeting of top Group of 7 diplomats gathered in Japan and vowed to address China’s growing assertiveness together. But Mr. Xi has still been getting some of the reaction he and other Chinese officials had hoped for in recent months, visually chipping at some of the alliances that underpin Washington’s influence.

During Mr. Xi’s meeting with Mr. Lula, the Brazilian leader railed against the continued dominance of the U.S. dollar in trade and paid a visit to a research center for China’s telecommunications giant, Huawei, which is under sanctions from the United States. Mr. Macron hailed European autonomy and warned against being dragged by the United States into a war over Taiwan. And Prince Mohammed praised China’s growing “constructive role” in the Middle East, a not so subtle dig at the United States and its strained relationships in the region.

At the same time, Chinese state media has railed against the “perils” and “abuse” of American hegemony and criticized the United States on human rights, racism and gun violence. It has seized on the leaked Pentagon documents to highlight how Washington has been spying on its allies. And it has mocked the Biden administration for holding a summit on democracy last month, describing U.S. democracy as “troubled,” “messy” and “in constant decline.”

Beijing’s harsher line reflects its frustrations over a series of U.S. moves, particularly in relation to Taiwan, the self-governing island claimed by China. Taiwan’s president, Tsai Ing-wen, visited the United States earlier this month and met with Kevin McCarthy, the speaker of the House of Representatives. On Monday, Taiwan said it had clinched a deal to buy up to 400 U.S. anti-ship missiles to help counter a potential Chinese invasion.

Then there are the joint military drills the United States is conducting with the Philippines, the largest in decades.

Those moves compound deeper resentments that center on U.S. restrictions of advanced semiconductor exports to China and growing security ties between the United States and countries on China’s periphery such as Japan, South Korea, Australia and India.

To Chinese officials, American pleas for renewed diplomatic engagement — including a long-awaited call between Mr. Biden and Mr. Xi — ring hollow in the face of what they view as rising hostility and provocations. High-level talks can only proceed after the United States has demonstrated “credible sincerity with concrete actions,” Chinese state media said last week.

“The responsibility for the current difficulties in China-U.S. relations does not lie with China,” Wang Wenbin, a spokesman for the Chinese Foreign Ministry, said recently when asked about resuming dialogue with Washington and the potential rescheduling of a visit to Beijing by Secretary of State Antony J. Blinken that was called off after the emergence of a suspected high altitude Chinese spy balloon over the continental United States in February.

“The U.S. needs to stop interfering in China’s internal affairs and harming China’s interests, and stop undermining the political foundation for our bilateral relations while stressing the need to put ‘guardrails’ on the relationship,” Mr. Wang added.

The Biden administration says it wants to establish “guardrails” to prevent an incident from flaring over a misunderstanding in heavily contested areas such as the South China Sea and the Taiwan Strait, where China conducted live-fire drills in response to Ms. Tsai’s visit. Without protocols and direct lines of communication, the risk for an incident will remain high as U.S. and Chinese forces patrol the region regularly, and often at close range.

Beijing views guardrails as another form of containment because they would disclose to the United States how far it can be pressured without triggering a military response. China would prefer its red lines to remain ambiguous and leave Washington guessing.

China suspended most military dialogue with the United States last August following former House Speaker Nancy Pelosi’s visit to Taiwan. The Pentagon said as recently as last week that Beijing had declined requests for engagement with Defense Secretary Lloyd J. Austin III and the chairman of the Joint Chiefs of Staff, Mark A. Milley.

Mr. Blinken expressed some optimism that high-level talks would resume.

“My expectation would be that we will be able to move forward on that. But it does require China to make clear its own intentions in doing that,” he said on Tuesday speaking to reporters at a meeting of the Group of 7 nations in Japan.

Analysts say Mr. Xi likely believes he has nothing to gain from speaking to President Biden at this moment, particularly as negative views on China in the United States appear increasingly entrenched.

“Xi clearly believes that engagement for engagement’s sake is a fool’s errand. The time for talk has passed. Instead, it’s time for Beijing to batten down the hatches,” said Craig Singleton, a senior China fellow at the nonpartisan Foundation for Defense of Democracies. “Simply put, there is no going back to the way things were, so Xi must now prepare China for a more fraught future.”

Minxin Pei, a professor at Claremont McKenna College who studies Chinese politics, said it is possible that Beijing will re-engage with Washington once it feels it has more leverage. That could come after Beijing has deepened ties with more nonaligned countries like Brazil or after it has widened splits in Europe over how closely to follow the United States in its tougher stance toward China.

“China wants to engage the U.S. from a position of strength, and China is clearly not in that position now,” Mr. Pei said. “If anything, America’s success in rallying allies and waging the tech war against China proves that it is still far more powerful than China and has more tools at its disposal.”

China is now trying to tread a fine line between snubbing the United States diplomatically and trying to persuade central bankers and investors that it is open for business again after years of stringent Covid measures.

Yi Gang, China’s central bank governor, met with Jerome Powell, the chairman of the Federal Reserve, on the sidelines of a World Bank and International Monetary Fund meeting in Washington last week to discuss their countries’ economies. Plans are also in the works for Treasury Secretary Janet Yellen and Commerce Secretary Gina Raimondo to visit China.

But Mr. Yi had grievances, too. He criticized Western countries from diverting trade away from China toward geopolitical allies instead, using the term “friend-shoring” in a statement to the International Monetary and Financial Committee on Friday.

Chinese analysts say the prospects of Sino-U.S. relations improving anytime soon remains remote. The modest progress Mr. Xi and Mr. Biden achieved after meeting in Indonesia last November is all but gone following the balloon incident and Ms. Tsai’s visit to the United States, said Wu Xinbo, dean of international studies at Fudan University in Shanghai.

“In China’s view, though Biden showed a good attitude in Bali, he is not strongly willing to improve Sino-U.S. relations,” Mr. Wu said. “China thinks the U.S. has neither the sincerity nor the ability to improve relations.”

Olivia Wang contributed reporting.