U.S. President Barack Obama (L) shakes hands with China's President Xi Jinping in front of U.S. and Chinese national flags during a joint news conference at the Great Hall of the People in Beijing November 12, 2014. (Petar Kujundzic/Reuters)

FOLLOWING A summit that produced an impressive batch of agreements on climate change, military exchanges, trade and visa liberalization, President Obama and Chinese President Xi Jinping spoke expansively Wednesday about the ability of their countries to collaborate. “China is ready to work with the United States to make efforts in a number of priority areas,” said Mr. Xi. Chimed Mr. Obama: “We’ve shown that U.S.-China cooperation can end up not only being good for the two countries but for the world as a whole.”

The accords are good news, particularly for the troubled causes of preventing climate change and expanding free trade. But it was also refreshing to see that Mr. Xi and Mr. Obama did not allow their agreements and upbeat rhetoric to prevent them from airing their differences on human rights. Mr. Xi was particularly blunt, dismissing Hong Kong’s ongoing demonstrations for free elections as “an illegal movement” and declaring that “foreign countries should not interfere in those affairs in any form or fashion.” He also said Western media have only themselves to blame for their problems in obtaining visas for their journalists.

Mr. Obama was more diplomatic, reiterating the U.S. “one-China” policy on Taiwan and stressing that “we are not in favor of independence” for Tibet. But Mr. Obama did bring up his discussions with Mr. Xi on human rights, saying that “we did encourage . . . steps to preserve the unique cultural, religious and linguistic identity of the Tibetan people.” He also spoke out on Hong Kong, rejecting the idea — pushed hard by Chinese state propaganda — that the United States fomented the protests and adding that “[we] are going to consistently speak out on the right of people to express themselves” and support Hong Kong elections that “are transparent and fair and reflective of the opinions of people there.”

We found Mr. Xi’s comments to be offensive and wrong. Among other things, China committed itself to freedom of assembly and expression as well as elections in its 1984 agreement with Britain on the handover of Hong Kong — which means that Western governments have not just a right but an obligation to “interfere” when Beijing does not respect its commitments. For their part, Chinese officials will be irked by Mr. Obama’s comments, which offered hope and encouragement not just to human rights activists in Tibet and Hong Kong but also around Asia.

The salient point here is that neither president’s comments caused the agreements they struck to crumble. Mr. Xi is working with Mr. Obama because it is in China’s interest to do so, not because Washington soft-pedals concerns about human rights. Similarly, it makes sense for the United States to expand trade and exchange commitments with Beijing on controlling carbon emissions, despite China’s hostile propaganda and the bullying of U.S. journalists.

In short, it’s possible for Mr. Obama to speak forthrightly in support of human rights in China and to press Mr. Xi about matters such as Tibet and Hong Kong while still partnering with Beijing in areas of mutual interest. It’s a lesson the Obama administration has been slow to learn, but the president’s performance Wednesday was ­auspicious.