MEXICO CITY, Sept 7 (Reuters) – Mexican Finance Minister Luis Videgaray has stepped down, pushing out of the government the closest ally of President Enrique Pena Nieto, who was strongly criticized for Donald Trump‘s controversial visit last week.

A finance ministry spokeswoman said Videgaray, who officials say was the architect of the Republican presidential candidate’s visit, was stepping down after the government said Pena Nieto would hold a news conference later on Wednesday morning.

Pena Nieto was pilloried on social media for hosting Trump at short notice last Wednesday, after the New Yorker had spent much of the past year launching verbal attacks on Mexico as a country sending rapists and drug runners across the U.S. border.

With economic growth sluggish, the president’s popularity at record lows and tensions palpable between the finance minister and other Cabinet members, rumors of Videgaray’s impending departure have bubbled under the surface in Mexico for months.

Trump has sparked fury with threats to make Mexico pay for a border wall, carry out mass deportations of illegal immigrants and rewrite trade treaties – and the fiery reaction to the visit had increased pressure on Pena Nieto to make changes.

Two people familiar with the matter said that Videgaray, who had once been one of the favorites to succeed Pena Nieto, will be replaced by Jose Antonio Meade, a former finance minister currently serving as the minister for social development.

The spokeswoman could not confirm Meade’s appointment.

Senior diplomats said Videgaray had been instrumental in arranging the Trump visit. The 48-year-old, who ran Pena Nieto’s election campaign, was widely seen as the president’s top aide, with a huge influence on a broad swath of policy.

The government had hoped to impress upon Trump the need to moderate his tone, reconsider his more divisive campaign proposals and better understand Mexico’s concerns during the 70-minute talk he held with Pena Nieto in Mexico City.

But within hours of departing the country, Trump was telling a cheering crowd of supporters in Phoenix, Arizona, that Mexico would pay for the border wall “100 percent,” prompting fresh ridicule of Pena Nieto at home.

Videgaray, who has also been rumored as a potential 2017 gubernatorial candidate for the ruling party in the State of Mexico, a populous region next to the capital, will not take another public post, the spokeswoman for his ministry said.

The resignation comes shortly before the government presents its 2017 budget with cuts needed to restore confidence after rating agency Standard & Poor’s last month said it could cut the country’s credit rating following a marked increase in debt.

Mexico’s economy has consistently underperformed expectations during Videgaray’s tenure.

The economy contracted in the second quarter for the first time in three years, and the collapse in global oil prices has sabotoged Pena Nieto’s hopes that a landmark energy reform would spur a wave of foreign investment. (Reporting by Dave Graham; Editing by Jonathan Oatis)