BEIJING — The White House pushed very hard for President Xi Jinping to take questions during his news conference with President Obama at the end of their two days of meetings Wednesday. It did not want a repeat of the stilted, scripted encounter Mr. Obama had with Mr. Xi’s predecessor, Hu Jintao, in 2009 on his first trip to China as president.

What the White House got was Xi Jinping, Unplugged, and that may have been more than it bargained for.

Discarding his standard bromides about the importance of new “major-country” relations between the United States and China, the Chinese leader delivered an old-fashioned lecture. He warned foreign governments not to meddle in the pro-democracy movement in Hong Kong and foreign journalists to obey the law in China.

Mr. Xi’s thinly concealed anger turned a news conference that should have been a victory lap for two leaders who had just had a productive meeting into a riveting example of why the relationship between the United States and China remains one of the most complicated in the world. The determination to work together belies deep-rooted historical grievances; the happy talk of win-win solutions masks a ferocious rivalry.