Mr. Qi’s views are an example of the complex, sometimes contradictory attitudes toward the United States held across China — a love-hate relationship that presents an unusual challenge to the ruling Communist Party and its leader, Xi Jinping, as they try to defend their image at home amid the bruising trade war.

Divided popular opinion — and ambivalence about America, even among some of its most ardent fans (and critics) — makes it difficult for Beijing to come down too hard on the United States. But if it does too little, the party risks looking weak.

Chinese people have long looked to America as a source of inspiration, with its gleaming skyscrapers, financial power and unparalleled military might. But they also increasingly see it as a strategic rival — a view partly fueled by pride in China’s rise, and by the party’s propaganda organs, which have long depicted America as a hostile, imperialist country that has tried to keep China down.

“China now has the No. 2 mentality,” said Yun Sun, a China analyst at the Washington-based Stimson Center. “It’s only natural for No. 2 to want to surpass No. 1.”

Even in China’s authoritarian political system, public opinion must be carefully managed. If leaders push an anti-American message too far, they run the risk of nationalist sentiment spiraling out of control. That would limit their options in talks with Washington by forcing them to adopt a tough posture.