MEXICO CITY — The risks could be enormous, but they haven’t swayed Mexican President Andrés Manuel López Obrador.

Mexican diplomats and opposition figures have warned Mr. López Obrador against traveling to Washington this week to thank President Donald Trump and celebrate the beginning of a new trade deal between the two countries and Canada.

The visit, they have said, was an incomprehensible choice in the middle of a pandemic and global economic crisis, coming with the risk of public humiliation at the hands of Mr. Trump, who has called Mexican immigrants “rapists” and “animals,” and has said that Mexico is “not our friend.”

Still, Mr. López Obrador said he would move ahead with plans to fly to Washington and greet Mr. Trump on Wednesday.

“President Trump’s discourse regarding Mexico has been more respectful than it was previously, for which we are very grateful,” Mr. López Obrador said in a recent news conference. “I am also going to give thanks for the U.S. government’s respectful treatment of us.”

Bernardo Sepúlveda, a former foreign minister, wrote in an open letter to the government that the trip would “negatively affect national interests” in the long term, noting that Mr. Trump has been “stigmatizing, offending and humiliating Mexican immigrants.”

The visit could also alienate the Democratic Party in the run up to the November elections. Mr. López Obrador does not plan to meet with Joseph R. Biden Jr., the former vice president and the presumptive Democratic nominee. Canadian Prime Minister Justin Trudeau declined the invitation to attend the summit, citing scheduling conflicts.

Some Mexican politicians and pundits view the trip as a capitulation to a leader who has routinely disparaged the country and undermined its interests. Jorge Castañeda, another former foreign minister, said the visit would not yield many benefits for Mexico, and that “Trump is using López Obrador for his own political ends.” And Arturo Sarukhán, former Mexican ambassador to the United States, called the trip “a colossal error, electorally, diplomatically and strategically.”

But the roasting has not deterred Mr. López Obrador, long a divisive figure in Mexican politics. He has insisted that there is more to gain from the visit than his critics will admit.

“Mexico needs to have a solid relationship with the United States, no matter who is the president,” said Erick Ordoñez, 29, a supporter of Mr. López Obrador who grew up in Chiapas and now lives in Barcelona. Mr. Ordoñez said the visit could help bring more foreign investment into Mexico and lift the economy.

“We need to benefit the Mexican people, with plans for trade, for creating jobs, for U.S. investment into Mexico,” he said.

Credit…Doug Mills/The New York Times

Mr. López Obrador has touted the importance of celebrating the revised North American Free Trade Agreement, which went into effect last week, at a moment when Mexico is in dire need of an economic revival. Mr. Trump has also done Mexico a few favors of late, sending hundreds of ventilators across the border and agreeing to help the country meet an obligation to cut oil production under a recent international agreement.

“It’s a big gamble,” said Luis Rubio, the president of the Mexican Council of International Affairs. “If it doesn’t go well, if Trump talks about ‘the wall’ or something in that vein, López Obrador will be embarrassed and will return with his tail between his legs.”

The timing of the trip has also been the subject of scrutiny among many in Mexico. The United States is only a few months away from a national election, coronavirus infections are surging on both sides of the border and officials close to both presidents have tested positive for the virus.

Adding to the trip’s health risks is Mr. López Obrador’s preferred mode of transportation: in keeping with his image as a frugal public servant, the president plans to fly to Washington on a commercial jet.

“You could become infected,” said Valeria Burgos, a small-business owner in Cuernavaca, a city south of Mexico’s capital. “This is not the moment for heads of state to be leaving their countries.”

But Ms. Burgos, 27, acknowledged that there may never be an ideal moment for a Mexican president to meet with Mr. Trump. During the U.S. elections in 2016, there was a similar uproar over former Mexican president Enrique Peña Nieto’s decision to host Mr. Trump at Los Pinos, the Mexican White House.

“That was a total disaster and an insult to Mexicans,” Ms. Burgos said. “And that was in our country, imagine how it will be when our president goes to Trump’s country.”

Mr. López Obrador won the presidency in 2018 with the largest margin of victory in more than a decade, but his popularity has slipped in recent months, as concerns over his handling of the pandemic have grown. Still, the Mexican president enjoys the approval of close to 60 percent of the population and a rabidly loyal base.

“For Mexico, it’s very politically important that Andrés Manuel is close to the United States,” said José Paniagua, a longtime supporter of Mr. López Obrador who lives in Mexico City. “This is a country that always has and always will be our neighbor,” Mr. Paniagua said.

“If the presidents didn’t meet it would hurt us both more because in the end, Mexico and the United States will always be together.”