Republican presidential nominee Donald Trump is headed to Mexico, making a surprise visit to meet the president of a nation he derided at the start of his White House campaign as a source of rapists and criminals coming to the United States.

Trump's visit on Wednesday follows an invitation from President Enrique Pena Nieto, who has repeatedly criticised Trump's immigration and border policies and compared him to Adolf Hitler.

Protests are expected in Mexico City near the famous Plaza de San Angel statue, while Mexicans vented their anger over the visit on social media.

Both a former Mexican president and first lady bluntly told Trump that he was not welcome, despite Pena Nieto's hospitality.

Former Mexican President Vicente Fox called the trip a "political stunt".

Margarita Zavala, wife of former president Felipe Calderon also wrote on Twitter: "We Mexicans have dignity, and we reject your hate speech."

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.

Trump announced on Tuesday night that he would make the Mexico visit, accepting on short notice an invitation offered last week by Pena Nieto, who also invited Democratic candidate Hillary Clinton.

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

READ MORE: Will Trump's minority outreach work?

"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.

"And 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."

Trump has promised, if elected, to deport millions of immigrants who are in the United States illegally, force Mexico to build a wall to secure the 3,000-km border and renegotiate the NAFTA trade agreement to make it more favourable to the United States.

He responded to Vicente Fox's criticism on Twitter, saying the former president had, like Pena Nieto, invited him to come.

Fox shot back with a tweet of his own, saying he had invited Trump to "come and apologise to all Mexicans. Stop lying! Mexico is not yours to play with, show some respect."

Pena Nieto has been sharply critical of Trump's immigration policies, particularly the Republican's plans to build a wall and have Mexico pay for it.

In a March interview, he said that "there is no scenario" under which Mexico would do so and compared Trump's language to that of dictators Adolf Hitler and Benito Mussolini.

He had a different tone late on Tuesday, tweeting, "I believe in dialogue to promote Mexico's interests in the world and, principally, to protect Mexicans wherever they are".

Source: Al Jazeera News and agencies