BEIJING — President Trump heaped praise on President Xi Jinping of China on Thursday, blaming past American administrations for China’s yawning trade surplus with the United States and saying he was confident that Mr. Xi could defuse the threat from North Korea.

Mr. Trump’s warm words, on a state visit to China replete with ceremony but short of tangible results, showed a president doubling down on his gamble that by cultivating a personal connection with Mr. Xi, he can push the Chinese leader to take meaningful steps on North Korea and trade.

In public, Mr. Trump projected an air of deference to China that was almost unheard-of for a visiting American president. Far from attacking Mr. Xi on trade, Mr. Trump saluted him for leading a country that he said had left the United States “so far behind.” He said he could not blame the Chinese for taking advantage of weak American trade policy.

Behind closed doors, American officials insisted, Mr. Trump forcefully confronted Mr. Xi about the chronic trade imbalances between the two countries. He also pressed China to take tougher measures toward North Korea, including a suspension of oil shipments.