Donald Trump announced he would travel to Mexico on Wednesday to meet its president, just hours ahead of giving a much-anticipated speech in Arizona on immigration.
The Republican presidential nominee's surprise trip south of the border comes as debate about his hardline immigration policies is reaching fever pitch.
Although his visit holds potential political peril, Trump could seize control of the campaign narrative at a crucial time, showing a willingness to engage diplomatically on a sensitive issue at the heart of his campaign.
"I have accepted the invitation of President Enrique Pena Nieto, of Mexico, and look very much forward to meeting him tomorrow," Trump posted on Twitter on Tuesday.
Mexico's presidential office confirmed the visit, posting its own tweet in Spanish to say the billionaire New York real estate tycoon "has accepted the invitation and will meet tomorrow privately with the President @EPN."
Pena Nieto's office said in a statement that he had sent invitations to Trump as well as his Democratic rival Hillary Clinton.
Her campaign has announced no plans for a visit, with an aide on Tuesday saying Clinton "looks forward to talking with President Pena Nieto again at the appropriate time."
Trump has routinely assailed Mexican immigrants who illegally cross the border into the United States. Hardline immigration policies including calls for deportations are a key plank of his campaign.
Trump could be sensing an opportunity in the visit as he mulls whether to soften his positions on immigration, particularly the call early in his campaign to deport some 11 million undocumented immigrants living in the shadows.
Any Trump-Pena Nieto meeting could be an awkward affair. In rally after campaign rally, Trump has pledged to "build a wall" on the US southern border if he becomes president and to force Mexico to pay for it.
Pena Nieto for his part has likened Trump to "Hitler and Mussolini" and slammed the Republican nominee for his isolationist positions. And in a July interview, he told CNN that "there is no way that Mexico could pay for a wall like that."
Trump used some of the most incendiary language of his campaign when launching his White House bid last year, describing Mexicans as drug dealers, "rapists" and other criminals.
He is scheduled to deliver what is billed as a crucial speech on Wednesday evening in Phoenix, Arizona, seen as an opportunity to clarify his positions on immigration.
In recent weeks he has expressed willingness to soften his hardline stance to a "fair and humane" policy ahead of November's election.
But Trump has vacillated between reaching out to minorities and returning to the anti-immigration rhetoric that goes down well among his most ardent supporters, mainly white working-class males.
That now looms as an obstacle as he seeks to expand his base in the general election contest at the expense of Clinton, who has accused Trump of fueling xenophobia and racism.
The recent tweaks to Trump's tone have included a change from insisting on removing millions of the undocumented to promising deportations of those immigrants with criminal records.
Trump's new campaign director, Kellyanne Conway, said there has been little real change in the central tenets of Trump's immigration platform, including "no amnesty" for those in the country illegally.
But she stressed Trump was committed to a "fair and humane" approach to securing America's borders.
Trump himself on Tuesday repeated his signature campaign promise to build a wall on the US border with Mexico.
"From day one I said that I was going to build a great wall on the SOUTHERN BORDER, and much more," he posted on Twitter. "Stop illegal immigration. Watch Wednesday!"