Ildefonso Guajardo Villarreal, the Mexican economy secretary, at a news conference after signing an agreement in Rio de Janeiro. Thomson Reuters During a panel discussion on Wednesday night, Mexico's economic minister, Ildefonso Guajardo Villarreal, said his country was prepared to "talk to the devil" if Republican presidential nominee Donald Trump wins the US election in November.

Villarreal made the statement during the Americas Society/Council of the Americas Pacific Alliance forum in New York City, where the presidents of Peru, Chile, and Colombia, with Villarreal standing in for Mexican President Enrique Peña Nieto, discussed how to secure investment and spur productivity in their countries.

"We cannot afford to risk a very important bilateral agreement," Villarreal said. "If we have to talk to the devil to guarantee the safety of the Mexican people, Mexico will talk to the devil."

Villarreal's comments are the latest entry in Mexico's ongoing adjustment to Trump's candidacy. The GOP nominee kicked off his campaign last year by accusing Mexico of, among other things, sending "rapists" and other criminals across the border.

Since then, Mexican officials have both criticized Trump and reaffirmed their commitment to the US-Mexico relationship. Mexico is the US's third-largest trading partner.

Villarreal on a panel with Peruvian President Pedro Pablo Kuczynski, center, and Colombian President Juan Manuel Santos. AS/COA

Mexican attitudes toward Trump have been particularly fraught since the Republican candidate's brief visit to Mexico City earlier this month.

The visit was widely seen as an embarrassment for the Mexican government, and Peña Nieto was excoriated by many Mexicans. Finance Minister Luis Videgaray, who is thought to have orchestrated Trump's trip, stepped down in the aftermath.

Others throughout the region have expressed reservations about a potential Trump presidency.

Peru's central-bank chief said earlier this month that Trump's stated policies could take the world back to the era of the Great Depression and that such a possibility "gives me the goosebumps." Peru's president, Pedro Pablo Kuczynski, expressed similar concerns about the damage Trump could do to US-Latin American relations. Peña Nieto and two former Mexican presidents have compared the GOP candidate to Hitler.

Colombian President Juan Manuel Santos struck a more measured tone at the Wednesday-night forum, saying many people "say one thing campaigning but do another in office once they realize what's possible" in government.

(Reporting for Reuters by Dion Rabouin; Editing by Sandra Maler)