MEXICO CITY (AP) — On Mexican soil for the first time as the Republican presidential nominee, a firm but measured Donald Trump defended the right of the United States to build a massive border wall along its southern flank, standing up for the centerpiece of his immigration plan in a country where he is widely despised.

But within hours of Trump's visit, a dispute arose over the most contentious part of the billionaire's plans to secure the U.S. southern border — his insistence that Mexico must pay to build that wall.

When answering questions from adjacent lecterns before a Mexican flag after his meeting at the official residence of the country's president, Enrique Pena Nieto, Trump said Wednesday the two men didn't discuss who would pay for a cost of construction pegged in the billions.

Silent at that moment, Pena Nieto later tweeted, "At the start of the conversation with Donald Trump I made it clear that Mexico will not pay for the wall."

With the meeting held behind closed doors, it was impossible to know who was telling the truth. But the difference in how Trump and Pena Nieto recalled their talk was an example of the political risk taken on by two unpopular politicians who arrived at the meeting having spent months quarreling from afar.

Trump began his campaign by deriding Mexico as a source of rapists and criminals, and piled on in the months to come as he attacked Mexico over free trade, illegal immigration and border security. Pena Nieto responded by condemning Trump's language, saying those were the sort of words that gave rise to Adolf Hitler.

Pena Nieto did not repeat such criticism Wednesday, but acknowledged Trump's comments had "hurt and affected Mexicans."

"The Mexicans deserve everyone's respect," he said.

The trip and the later dispute, arriving 10 weeks before America's presidential Election Day, came just hours before Trump was to deliver a highly anticipated speech in Arizona about illegal immigration. That has been a defining issue of his presidential campaign, but also one on which he's appeared to waver in recent days.

Trump stayed on script after the meeting, reading a statement from notes and politely answering shouted questions from reporters about his promise to force Mexico to pay for a wall along the border between the two countries.

"We did discuss the wall. We didn't discuss payment of the wall," Trump said.

Writing later on Twitter, Pena Nieto said the subject was among the first things the men discussed. He has for months said "there is no scenario" under which Mexico would pay for the wall.

"From there, the conversation addressed other issues, and developed in a respectful manner," he added.

Those issues included the North American Free Trade Agreement, which Trump has called the worst trade deal in history. Pena Nieto suggested there was room to improve the trade deal, while the New York businessman promised to promote trade deals that would keep jobs in the Western Hemisphere — a departure from his standard "America First" rhetoric.

Trump's presence Wednesday, his first meeting with a head of state abroad as a presidential candidate, sparked anger and protests across Mexico's capital city. Former Mexican President Vicente Fox bluntly told the celebrity businessman that, despite Pena Nieto's hospitality, he was not welcome.

"We don't like him. We don't want him. We reject his visit," Fox said on CNN, calling the trip a "political stunt."

Pena Nieto was less combative as he addressed reporters alongside Trump. He acknowledged the two men had differences and defended the contribution of Mexicans working in the United States, but he described the conversation as "open and constructive." He and Trump shook hands as the session ended.

Pena Nieto's performance came in for immediate condemnation from his many critics in Mexico.

"Pena ended up forgiving Trump when he didn't even ask for an apology," said Esteban Illades, the editor of Nexos magazine. "The lowest point of the most painful day in the history of the Mexican presidency."

After saying during his Republican primary campaign he would use a "deportation force" to expel all of the estimated 11 million people living in the United States illegally, Trump suggested last week he could soften that stance.

But he still says he plans to build a huge wall — paid for by Mexico — along the two nations' border. He is under pressure to clarify just where he stands in the Wednesday night speech, which had been rescheduled several times.

Trump's running mate, Indiana Gov. Mike Pence, told CBS earlier in Wednesday that Trump would make clear "that there will be no path to legalization, no path to citizenship. People will need to leave the country to be able to obtain legal status or obtain citizenship."

Campaigning in Ohio, Democrat Hillary Clinton jabbed at Trump's Mexican appearance as she promoted her own experience working with foreign leaders as the nation's chief diplomat.

"People have to get to know that they can count on you, that you won't say one thing one day and something totally different the next," she told the American Legion in Cincinnati.

Her campaign jumped on Pena Nieto's later tweet, too.

"It turns out Trump didn't just choke," said Clinton campaign chairman John Podesta in a statement, "he got beat in the room and lied about it."

___

Peoples reported from Washington. AP writers Mark Stevenson and Maria Verza in Mexico City and Jill Colvin in Phoenix contributed to this report.