If anything, Mr. Xi faces even greater pressure than Mr. Trump from the tariffs, not to mention the angry protesters who have taken to the streets of Hong Kong. And for Mr. Kim, who is still nursing the wounds of his failed summit meeting with Mr. Trump in February, the Chinese president’s long-sought visit, which began Thursday, is another step in his return to the world stage.

Given all these crosscurrents, it seemed inconceivable that the timing of Mr. Xi’s visit to Pyongyang, the North Korean capital, was accidental. Administration officials said they expected the Chinese leader to try to make headway with Mr. Kim on the nuclear talks and then use that as leverage with Mr. Trump in the trade negotiations, when they meet at the Group of 20 gathering in Osaka.

Mr. Xi himself stoked those expectations, publishing a rare article on Wednesday in the North Korean ruling party’s official newspaper, Rodong Sinmun, in which he said China was willing to draw up a “grand plan” with the North Koreans that would “realize permanent peace” on the Korean Peninsula.

“If Xi can’t say something to Trump on trade, it would suggest that his visit to Pyongyang was for naught,” said Jonathan D. Pollack, an expert on China and North Korea at the Brookings Institution. “Xi, like everyone else in Asia, is trying to reposition himself in light of a very unpredictable American president.”

Yet on both fronts, the Chinese president faces an uphill battle.

Mr. Kim’s talks with Mr. Trump in Hanoi, Vietnam, broke down after it was clear there was a chasm between the North Korean and American positions — one that China can hardly bridge. And while there are also signs that the trade war is causing economic damage in the United States, particularly among farmers and manufacturing workers, the president himself seems sanguine that tariffs are a political winner, allowing him to continue to drive a hard bargain with China.