BEIJING — For more than a year, China has railed against South Korea, calling for boycotts of its products over Seoul’s decision to let the United States deploy an antimissile system, which Beijing fears threatens its own security.

On Tuesday, however, China abruptly changed course, essentially saying “never mind,” as the two countries agreed to end their dispute even though South Korea is keeping the system in place.

China’s unexpected move to settle the rancorous dispute could scramble President Trump’s calculations about how to deal with allies and North Korea on the eve of his first trip to Asia.

The decision, by the newly empowered Chinese president, Xi Jinping, appeared to reflect a judgment that China’s continued opposition to the deployment of the American missile defense system was not succeeding in fraying the South Korean government’s alliance with Washington.