David Jackson and David Agren

USA TODAY

MEXICO CITY — After a surprise, last-minute meeting in Mexico City, Republican presidential nominee Donald Trump and Mexican President Enrique Peña Nieto agreed to disagree Wednesday on such politically contentious topics as immigration and trade — and disputed whether they discussed Trump's claims that Mexico would pay for his proposed border wall.

While Trump told reporters he and Peña Nieto "didn't discuss" financing the wall — "that will be for a later date" — the Mexico president later contradicted the GOP candidate on Twitter, saying that "at the beginning of the conversation with Donald Trump, I made clear that Mexico would not pay for the wall."

Speaking just hours before a highly anticipated speech in Phoenix on immigration, Trump declared that the United States has the right to build a wall to block the flow of immigrants who have committed crimes, a proposal that has drawn criticism from many Mexican leaders and offended sensibilities south of the border.

"We recognize and respect the right of either country to build a physical barrier or wall on any of its borders to stop the illegal movement of people, drugs and weapons," the Republican nominee said.

Trump also disagreed with Peña Nieto on the North American Free Trade Agreement, saying the deal has benefited Mexico more than the United States and needs to be changed.

Trump, who has described some Mexican immigrants as criminals and rapists, also went out of his way to praise Mexicans and Mexican-Americans, saying they are "beyond reproach" and "spectacular, hardworking people."

Mexicans not happy their president will meet with Trump

Peña Nieto offered a different analysis of border issues, calling them a "shared challenge" between the United States and Mexico and noting that weapons and cash for the drug trade flow into Mexico from the United States.

He also disputed Trump's criticisms of the NAFTA agreement involving the U.S., Mexico and Canada, saying all countries have benefited, though he added that the deal can always be improved.

"We may not agree on certain topics," he said at one point.

The Mexican president, who once likened Trump to Hitler and Mussolini, said he and the Republican presidential nominee met in order to get to know each other.

John Podesta, campaign chairman for Democratic nominee Hillary Clinton, mocked Trump over the wall dispute with Peña Nieto, saying the Republican "didn't just choke, he got beat in the room and lied about it."

Trump spokesman Jason Miller said the meeting was "the first part" of a discussion and "not a negotiation."

"It is unsurprising that they hold two different views on this issue, and we look forward to continuing the conversation," Miller said in a statement.

Trump's visit inspired protests in Mexico and sparked criticism of Peña Nieto. The meeting was high stakes for the Mexican president, whose approval rating hovers in the low 20s as his administration has been battered by corruption and conflict-of-interest scandals.

Members of the local legislative assembly declared the Republican presidential nominee "persona non-grata," while demonstrators gathered at the Angel of Independence monument near the U.S. Embassy. On Twitter, #DonaldTrumpNoEresBienvenido — Donald Trump You’re Not Welcome — became a trending topic.

While Trump has attacked Mexico throughout the campaign, he struck a more positive tone after his meeting with Peña Nieto, saying at one point that Mexicans were “amazing, amazing people.”

The Mexican president, meanwhile, said some of Trump’s comments on Mexico were “misinterpretations" — a comment that drew scathing attacks from Mexicans on social media who were expecting a more forceful response to a figure some have described as a threat to the country.

“Trump not only didn’t show repentance, he reaffirmed his agenda. EPN (Peña Nieto) not only did not show condemnation, he reaffirmed his passivity,” tweeted José Merino, a political science professor.

During discussion of the North American Free Trade Agreement, Trump said changes to the pact can help both the U.S. and Mexico in terms of job and growth. He added that "workers in both of our countries need a pay raise, very desperately."

Pushing back against Trump's attacks on NAFTA, Peña Nieto said 40% of the contents in Mexican manufactured goods originated in the United States and that the U.S. exports some $200 billion annually to Mexico.

“Commerce must not be a zero-sum game" in which one party wins while another loses, Peña Nieto said. “The border must transform into a regional asset.”

The trip was quite sudden. Departing from California, Trump flew south of the border to meet with the Mexican president before heading back north to Phoenix for what aides billed as a major speech laying out seemingly evolving views on immigration, particularly questions about the nation's 11 million undocumented immigrants.

Trump arrived at Los Pinos — the president’s residence — via helicopter from the Mexico City international airport, where his flight touched down at around 1:40 p.m. ET.

No U.S. flag graced the podium in the room where Trump and Peña Nieto addressed the media.

Trump's immigration speech Wednesday night comes after days of seemingly conflicting statements from the GOP nominee, including suggestions that he might soften his call for mass deportations of millions of people who are in the U.S. illegally.

While Trump has expressed support for formation of a "deportation force," he has recently suggested a "softening" of that position and told a group of Hispanic advisers on Aug. 20 that he wants to deal with the problem "humanely."

Donald Trump Jr.: My dad isn't 'softening' on immigration

The Obama administration, which has authorized record numbers of deportations, already puts a priority on immigrants with criminal records.

Tana Goertz, a senior adviser to the Trump campaign, said the GOP nominee is "the only candidate in this race who will stop illegal immigration, secure our border, end sanctuary cities, enforce our existing laws and stop American employers from hiring illegal workers"

Less than two and a half months before the election, Trump faces overwhelming opposition from Hispanic voters — the fastest-growing segment of the U.S. electorate, and potentially a decisive force in swing states like Arizona and Florida.

While seeking to reach out to Hispanics and other voters turned off by his hard-line immigration stance, Trump also wants to hold the support of conservatives who like the immigration policies he touted throughout his GOP primary campaign and believe the U.S. has permitted an "open borders" policy.

While preparing for his big speech, the New York businessman has maintained his pledge for a border wall and to have Mexico "pay for it."

Trump's visit to Mexico — and his first meeting with a foreign leader as presidential nominee — comes after months of attacks on the nation's southern neighbor and claims that it is "sending" criminals across the border.

Here's what Mexican leaders have said about Donald Trump

The Mexican president has said that he had invited both Trump and Clinton to meetings to discuss the Mexico-U.S. relationship.

Clinton, during a speech to an American Legion convention in Cincinnati Wednesday, did not cite Trump by name, but said his trip was more about politics than diplomacy. "It certainly takes more than trying to make up for a year of insults and insinuations by dropping in on our neighbors for a few hours and then flying home again," she said.

Clinton blasts Trump for rejecting 'American exceptionalism'

The Clinton campaign sought to amplify Trump's criticism of Mexico by sending out what it called "a big beautiful list of literally every tweet Donald Trump has sent about Mexico over the last two years."

Clinton spokeswoman Jennifer Palmieri said Trump "has painted Mexicans as rapists and criminals" and his past deportation plans would include children and the breakup of families that include U.S. citizens.

"What ultimately matters is what Donald Trump says to voters in Arizona, not Mexico," Palmieri said, "and whether he remains committed to the splitting up of families and deportation of millions."

Jackson reported from Washington