By Dave Graham

MEXICO CITY (Reuters) - Mexico's president rebuked Donald Trump as a threat to his country just hours after painting a positive picture of talks the two held on Wednesday to try to defuse tensions over the U.S. presidential hopeful's anti-Mexican campaign rhetoric.

President Enrique Pena Nieto had on Wednesday afternoon hailed as "open and constructive" the impromptu meeting he held with Trump, who later referred to the Mexican leader as his friend and a "wonderful" president.

But in a late evening television interview, an angry-looking Pena Nieto sought to defend himself against a broad swathe of 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," Pena Nieto 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."

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 as he sought to close the gap on Democratic rival Hillary Clinton.

The real estate mogul's accusations that Mexico sends rapists and drug runners to the United States, and his threats to build a border wall and tear up trade deals, have angered the government but his meeting with 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.

Pena Nieto had likened Trump to dictators Adolf Hitler and Benito Mussolini earlier this year. But his government said Trump understood its concerns at the meeting, making Pena Nieto's tense appearance on television the more surprising.

Story continues

"What we saw was a respectful attitude and discourse from Donald Trump," presidential spokesman Eduardo Sanchez had said earlier, arguing that progress was made on the issue of trade after prior threats by Trump to tear up the North American Free Trade Agreement (NAFTA).

"I think there was an advance in general," he added.

Still, Trump laid out a series of tough policies to tackle illegal immigration when he delivered his speech in Phoenix, Arizona, on Wednesday night.

He told a cheering crowd that Mexico would pay for the wall "100 percent" and 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.

Opposition politicians in Mexico rounded on Pena Nieto for hosting Trump.

"Instead of making him apologize, the government allowed (Trump) to complete the humiliation of the Mexicans," Ricardo Anaya, leader of the center-right opposition National Action Party, said on Twitter.

WALL TO WALL

Some Mexican officials also privately expressed reservations about the meeting with one former diplomat saying Pena Nieto had done Trump's campaign a favor.

During a joint news conference after their meeting, Trump said he and Pena Nieto had not discussed his demand that Mexico pay for the border wall.

But Pena Nieto later contradicted Trump, saying he had told the American that Mexico would not foot the bill, and he bristled during his television interview when asked why he had not made that clear at the news conference.

Speaking on condition of anonymity, a Mexican government official said the two men spoke English during the meeting and that Pena Nieto clearly explained to Trump the offense his comments had caused.

"He's a candidate that offended a lot of Mexicans, so that's the chemistry there was (between them)," the official said.

(Additional reporting by Ana Isabel Martinez, Lizbeth Diaz and Gabriel Stargardter; Editing by Simon Gardner)