President Enrique Pena Nieto hailed the impromptu meeting the two held to defuse tensions as "open and constructive" on Wednesday afternoon, and Mr Trump later referred to the Mexican leader as his friend and a "wonderful" president.
However in a late evening television interview, Mr Pena Nieto appeared angry as he sought to defend himself against criticism for his decision to invite the Republican candidate despite his repeated verbal attacks on Mexico.
"His policy stances could represent a huge threat to Mexico, and I am not prepared to keep my arms crossed and do nothing," the Mexican president said. "That risk, that threat, must be confronted. I told him that is not the way to build a mutually beneficial relationship for both nations."
Mr Trump's quick acceptance of an invitation, sent last Friday, took Mexico's government by surprise, and his visit to Mexico City came just hours ahead of a keynote speech on immigration in Phoenix, Arizona.
He laid out a series of tough policies to tackle illegal immigration, telling a cheering crowd Mexico would pay for the 2,000-mile border wall "100 per cent".
Mr Trump also told the crowd that if he wins the election anyone living illegally in the United States would be sent back to their home country and made to apply for re-entry. That would include millions of Mexicans.
Donald Trump's most controversial quotes
Show all 14
Mexico's government have been angered by Mr Trump's accusations that Mexico sends rapists and drug runners to the United States, and his threats to build the wall and tear up trade deals, but his meeting with Mr Pena Nieto on Wednesday gave him a chance to present himself in a more moderate light.
He spoke of Mexican-Americans in glowing terms and stressed the areas of common interest between the two countries even as he stuck to his message that he would put up the wall.
Earlier this year, Mr Pena Nieto likened Trump to dictators Adolf Hitler and Benito Mussolini. But his government said Mr Trump understood its concerns at the meeting, making Mr Pena Nieto's tense appearance on television the more surprising.
Join our commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies
Join our commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies