Mexico and China's leaders met on Thursday and committed to working together and strengthening ties, while agreeing to battle illegal drug trafficking between their nations and to push for more trade and investment.

The two met on the sidelines of the Asia-Pacific Economic Cooperation (APEC) summit in San Francisco.

China and Mexico's relationship has strengthened with time, Chinese President Xi Jinping said about the meeting, according to a post from the Asian country's embassy in Mexico, with Sino-Mexican relations becoming increasingly "mutually beneficial."

The post added that China "is willing ... to strengthen the articulation of strategies, (and) explore the potential for cooperation ... to promote bilateral relations to a higher level."

Mexico President Andres Manuel Lopez Obrador said the two leaders had "committed to continue maintaining good relations for the benefit of our people."

Lopez Obrador also met with Canadian Prime Minister Justin Trudeau on Thursday. The two discussed migration, Lopez Obrador wrote on social media, adding that Trudeau spoke about Canadian business leaders' confidence in investing in Mexico.

Lopez Obrador is scheduled to meet U.S. President Joe Biden on Friday.

The Biden administration has been seeking increased cooperation from both Mexico and China to stem the flow of fentanyl, a deadly opioid, and its precursor chemicals, which have fueled a sharp rise in overdose deaths in the United States.

Lopez Obrador and Xi agreed to combat illegal trafficking of precursor chemicals, Mexican Foreign Minister Alicia Barcena said in a post on social media network X.

They also agreed to promote trade and investment, she added.

The foreign ministry said in a separate post that Lopez Obrador spoke with Xi about two of his administration's keystone infrastructure projects, a solar energy development in the north of the country and the so-called Interoceanic Corridor to attract business to the south.

(Reporting by Kylie Madry and Valentine Hilaire; Additional reporting by Isabel Woodford; Editing by Josie Kao and Stephen Coates)