Mexican Finance Minister Luis Videgaray, who is believed to have come up with the idea of inviting Donald Trump, stepped down Wednesday amid the backlash against the controversial visit.

The resignation comes a week after Trump met President Enrique Peña Nieto.

Peña Nieto has said he was the one who decided to invite the two major US presidential candidates.

But local media reports said Videgaray was responsible.

Trump also inflamed sensibilities south of the border with his oft-repeated promise to build a border wall between the countries — and force Mexico pay for it.

A poll conducted after Trump’s visit found that 85 percent of Mexicans disapproved of the invitation, 72 percent said the visit damaged the government and 64 percent said it hurt their opinion of Peña Nieto.

The MIT-educated Videgaray had been Peña Nieto’s campaign manager in the 2012 election. The president tapped him to be his behind-the-scenes liaison to the Trump campaign, the Washington Post reported.

Videgaray and other aides considered an invitation to Trump a political risk that was worth taking, in case Trump won the election, sources told the paper.

Videgaray will be replaced by Social Development Minister Jose Antonio Meade, according to a person familiar with the situation, the Wall Street Journal reported.

Meade oversaw the Finance Ministry during the latter part of the administration of Felipe Calderon, Peña Nieto’s predecessor.