Mr Trump said they did not discuss his plan to make Mexico pay for the wall - a central plank of his campaign.
But Mr Pena Nieto later tweeted: "I made it clear Mexico would not pay for the wall."
After the meeting, Mr Trump flew to Phoenix, Arizona, to deliver a key speech on tackling illegal immigration.
At their joint press conference in Mexico City, Mr Pena Nieto said Mexicans had been hurt by some of Mr Trump's previous comments but he believed he now genuinely wanted to build relations.
The New York businessman called Mexicans "amazing" and "spectacular" people, in contrast to earlier comments branding Mexican migrants "rapists" and "murderers".
Forcing Mexico to pay for a wall has become a rallying cry among his supporters.
His Democratic rival Hillary Clinton said not bringing it up was a sign of cowardice.
"It turns out Trump didn't just choke, he got beat in the room and lied about it," she tweeted.
Mexicans tell Trump: 'You're not welcome!'
Donald Trump's Hispanic voter 'doomsday'
'Me gustan los tacos!': A Spanish phrasebook for Trump's visit
The Republican has seen his poll ratings slip since the party conventions last month.
Both nationally and in key states, he trails Hillary Clinton, who enjoys particularly strong support among minorities.
Donald Trump has called Mexico an enemy of the US, but on Wednesday he said Mexican President Enrique Pena Nieto was his friend.
That contrast illustrates how different Diplomatic Donald was from the firebrand candidate who tore through the Republican primaries by flogging his opponents for being soft on illegal immigration and border security.
If the goal of Mr Trump's visit to Mexico City was to represent his nation on the world stage without the kind of embarrassment or controversy that Hillary Clinton warns would be certain if he is elected, then his last-minute trip was a success.
But his surprise appearance south of the border may come with a price. It is likely to make it more difficult for him to back away from hard-line immigration positions that are unpopular among moderate voters.
Perhaps more grating for Mr Trump's diehard supporters is that he had the chance to confront the Mexican leader and instead spoke of protecting "hemispheric manufacturing" and avoided the subject of who would pay for the border wall.
Diplomatic Donald may not be the candidate they thought they were getting.
Mr Trump said his words to Mr Pena Nieto had been strong and straightforward.
He tried to put behind him his previous comments on Mexicans by saying those in the US had made a "great contribution".
"I have a great feeling for Mexicans. They are amazing people," he said.
Mr Trump said he had employed many Mexicans and that they were "spectacular people with strong values of faith and community".
He went on to list five points he had set out in his talks:
Mr Trump said: "We recognise and respect the right of either country to build a physical barrier or wall on any of its borders." But he said there was no discussion on who would pay for the wall.
He had earlier threatened to stop cash earned by Mexicans based in the US being sent home until the country paid for it to be built.
Mr Trump concluded by saying he was honoured by Mr Pena Nieto's invitation to visit, adding: "I call you a friend."
Mr Pena Nieto accepted there were border challenges but pointed out the massive contribution Mexicans have made to the US, and that "six million jobs rely on exports to Mexico".
He said: "My priority is to protect Mexicans wherever they may be. Mexicans in the US are honest people, hard-working people who respect their families, their community and the law. They deserve everybody's respect."
Mr Pena Nieto has invited both US candidates to visit, but has faced criticism at home over Mr Trump.
Ex-President Vicente Fox earlier told CNN: "We don't like him. We don't want him. We reject his visit."
Former First Lady Margarita Zavala tweeted: "We Mexicans have dignity, and we reject your hate speech."
At least two demonstrations have been planned in Mexico City.
Mexicans tell Donald Trump: 'You are not welcome'
What Trump has said about Mexico
"They're bringing drugs, they're bringing crime, they're rapists" - May 2015
Mexico is "ripping off the US more than almost any other nation" - February 2015
"Mexico continues to make billions on not only our bad trade deals but also relies heavily on the billions of dollars in remittances sent from illegal immigrants in the United States" - from his immigration plan
...and what Mexico has said about Trump
President Pena Nieto spoke out against Mr Trump's "strident rhetoric" in March, adding: "That's how Mussolini got in, that's how Hitler got in, they took advantage of a situation, a problem perhaps, which humanity was going through at the time, after an economic crisis."
His predecessor, Felipe Calderon, insisted: "Mexican people, we are not going to pay any single cent for such a stupid wall."
After Mr Trump vowed to reclaim all remittances derived from illegal wages, Mr Calderon's predecessor Vicente Fox, told the BBC: "Is Trump going to steal the money? How can any human being think like that? It's incredible."
US Republican candidate Donald Trump has defended his call for a wall on the Mexican border, during his visit to meet President Enrique Pena Nieto.