MEXICO CITY — Mexican President Enrique Pena Nieto said Thursday he will not attend a planned Jan. 31 meeting with President Donald J. Trump, hours after Trump tweeted that the meeting should be canceled if Mexico won’t pay for a border wall.

Pena Nieto’s message on Twitter ended days of uncertainty about how he would respond to Trump’s aggressive stance toward the country, and illustrated the challenges world leaders are likely to face in dealing with Trump’s voluble, Twitter-based diplomacy.

“This morning we have informed the White House I will not attend the working meeting planned for next Tuesday,” Pena Nieto tweeted. “Mexico reaffirms its willingness to work with the United States to reach agreements that benefit both nations.”

Later, Trump claimed he and Peña Nieto agreed jointly to cancel their planned meeting over disagreements about who will pay for Trump’s promised southern border wall. Trump made that assertion while speaking to a retreat for GOP House and Senate members in Philadelphia.

RELATED: Trump wants tax to pay for border wall

“Unless Mexico is going to treat the United States fairly, with respect, such a meeting would be fruitless, and I want to go a different route. I have no choice,” Trump said.

White House Press Secretary Sean Spicer said earlier Thursday that the administration would be looking to reschedule the meeting in the future and would “keep the lines of communication open.”

Earlier Thursday, Trump had tweeted that “If Mexico is unwilling to pay for the badly needed wall, then it would be better to cancel the upcoming meeting” in Washington D.C.

Trump said Wednesday he would start building a U.S.-Mexico border wall and has vowed to make Mexico pay for it. Mexico opposes the wall and has repeatedly said it won’t pay. In an interview this week, Trump said U.S. taxpayers would pay for the wall up front, and then the United States would seek reimbursement from Mexico.

Officials had said Mexico was “considering” canceling after the border wall announcement, but Trump appeared to beat Mexico to the punch in that game of brinkmanship.

Former foreign relations secretary Jorge Castaneda told local media that after Trump’s tweet, “Pena Nieto has no other choice but to say ‘I’m not going.'”

Trump’s unpredictable style appeared to catch Mexico’s normally quiet and cautious diplomacy off guard.

“I think that, in general, diplomacy is not conducted via Twitter,” Finance Secretary Jose Antonio Meade told Radio Formula.

Mexico’s best-known opposition politician, leftist Andres Manuel Lopez Obrador, tweeted that “in the face of Trump’s latest outburst, don’t go to the meeting, and submit an urgent complaint to the U.N. for human rights violations.”