US Republican candidate Donald Trump is to visit Mexico on Wednesday, hours before he details measures against illegal immigration in a speech.
Mr Trump tweeted that he was looking forward to meeting President Enrique Pena Nieto, who has invited both him and Democrat Hillary Clinton.
Mr Pena Nieto said dialogue would help “protect Mexicans wherever they are”.
Mr Trump has condemned Mexican migrants during his campaign and vowed to build a wall between the two countries.
He will visit Mexico in between a fundraising event in California and his immigration speech in Phoenix, Arizona, on Wednesday night.
The Republican has seen his poll ratings slip since the party conventions last month.
Both nationally and in key states, he trails Mrs Clinton, who enjoys particularly strong support among minorities.
The Mexican president said he had invited both candidates for talks and would meet Trump in private on Wednesday.
“I believe in dialogue to protect Mexican interests in the world and, principally, to protect Mexicans wherever they are,” he said.
Mrs Clinton’s campaign has not yet said if she will travel to Mexico.
Analysis – Anthony Zurcher, BBC North America Reporter
Mr Trump going to Mexico is a bold move. It shows he is willing to confront a nation he has mocked in the past. It may make him – dare I say? – look statesmanlike. And if Pena Nieto slams him afterwards, it could end up working to Mr Trump’s benefit.
There is no better way to get conservatives to rally around a candidacy than to have a foreign leader cast aspersions on the nominee.
One risk is that Mr Trump might say or do something controversial while there, although this likely will be a very tightly controlled meeting.
Another is that Mr Trump’s base, the voters who cheered as he called undocumented Mexican immigrants “rapists” and “drug dealers”, will consider this visit consorting with the enemy.
The stakes were already considerable for Mr Trump’s immigration speech on Wednesday night. They just got higher.
Mr Pena Nieto has previously accused Mr Trump of hurting US-Mexico relations and compared the Republican’s rhetoric to that of German Nazi leader Adolf Hitler.
Mr Trump has threatened to stop cash sent home by Mexicans based in the US until the country pays for the wall.
BBC Mexico Correspondent Katy Watson says the prospect has worried many Mexicans who rely on remittances from their families who live in the US.
Mr Trump blames Mexico for the disappearance of jobs from the US, with companies choosing to locate south of the border to take advantage of cheaper labour costs.
In June he expressed anger after a leading golf tournament was moved from one of his courses to Mexico, accusing the PGA Tour of putting “profit ahead of thousands of American jobs”.
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”, he said in February last year.
“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
Mr 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.”