SEOUL, South Korea — China’s visiting president, Xi Jinping, reminded South Koreans on Friday that their two countries had fought “shoulder to shoulder” against Japan more than four centuries ago, highlighting what analysts have called the main goal of his visit: unsettling America’s alliances in Northeast Asia.

Japan and South Korea are the United States’ closest allies in Asia, and the Obama administration has been struggling for months to thaw a chill in relations between them as it seeks to counterbalance China’s rise. Mr. Xi’s remarks were viewed by analysts as trying to take advantage of the rift.

“Whenever there was a crisis, Korea and China always helped each other and overcame the crisis together,” Mr. Xi told a group of students at the prestigious Seoul National University, which educates many students who will join the political elite. “Four centuries ago during the Japanese invasion,” he said, people of both nations had held Japan in “enmity” and had “marched together shoulder to shoulder to the battlefields.”