MEXICO CITY — President Trump called Mexican migrants rapists, threatened his neighbor with a trade war, kicked tens of thousands of asylum seekers out of the country, built up the border wall and promised to make Mexico pay for it.
Mexico’s president is a big fan.
So profound is his appreciation that when President Andrés Manuel López Obrador finally got on the phone for the first time with President-elect Joseph R. Biden Jr. last month, he made a point of praising the departing president.
“I must mention that we do have a very good relationship with the now president of your country, Mr. Donald Trump,” Mr. López Obrador said, according to two people with knowledge of the call, who spoke on the condition of anonymity to discuss internal matters. “Regardless of any other considerations, he respects our sovereignty.”
Concerned that Mr. Biden might be more inclined to meddle in Mexican affairs, Mr. López Obrador has spent the last several weeks preemptively poking the incoming administration in the eye.
He was among the very last global leaders to congratulate Mr. Biden on his victory, insisting on waiting “until all the legal issues are resolved.” He recently signed a law gutting the ability of U.S. drug agents to act in Mexico. And then, out of nowhere, Mr. López Obrador offered Julian Assange asylum.
His government also exonerated a former Mexican defense secretary charged with drug trafficking by American prosecutors, allegations the president said were “fabricated” by investigators who “did not act responsibly.”
Behind all those perceived slights is a fear that the Democrats are more likely to intervene to promote labor rights and clean energy, getting in the way of Mr. López Obrador’s ambitious agenda at home, according to two officials in his government who spoke on the condition of anonymity for fear of reprisals.
“It’s like a dog at the park: He’s gnashing his teeth and threatening you and growling in the hope that you won’t come close,” said Shannon O’Neil, a Mexico expert at the Council on Foreign Relations. “He’s trying to pre-emptively push back against engagement by the incoming Biden administration.”
In a statement, Roberto Velasco, who oversees the North American region at Mexico’s foreign ministry, said that the government has had several conversations with Mr. Biden’s transition team “highlighting the importance that both attach to a good bilateral relationship.”
He added: “Mexico will continue to work, within our Constitutional principles, to foster the best relationship between our country and the United States. Those who keep predicting bilateral conflicts will again be proved wrong.”
One of the surprising twists in a Trump presidency full of them has been how a Mexican leader who ran on a leftist, populist platform and once said Mr. Trump “stokes racism” came to regard him so highly.
By all appearances, the relationship is based more on pragmatism than on any deep personal friendship. The two men share a profound disinterest in the particulars of foreign policy and found common purpose in leaving each other alone.
The terms of their deal may not have been written, but they were clear. Mr. López Obrador enforced Mr. Trump’s hard-line immigration agenda and in exchange, the United States let him run Mexico as he pleased.
In a recent speech in Alamo, Texas, Mr. Trump bragged about how many Mexican soldiers Mr. López Obrador had sent to police the border. “I want to thank the great president of Mexico,” he said. “He is a great gentleman, a friend of mine.”
On style, too, the leaders were often aligned. Both campaigned on a promise to root out a corrupt elite, won with a coalition of voters disgusted with their country’s establishment and, once in office, painted the media and the opposition as enemies of their movement.
Just as Mr. Trump used Twitter to speak directly to his base, Mr. López Obrador takes control of the narrative by holding two-hour news conferences every day at which questions are often asked by sympathetic tabloid reporters or YouTubers.
And in 2006, Mr. López Obrador spent months leveling accusations of fraud after he lost the presidential election, going as far as to hold a fake inauguration for himself in the capital’s central square.
“He is, in a certain sense, very similar to Trump,” said Sergio Aguayo, one of Mexico’s leading human rights activists. “The understanding between them was emotional and practical.”
Mr. Biden is likely to ask more of Mr. López Obrador.
The president-elect is anticipating a surge of migration from Latin America in the coming year, driven by the global economic crisis and the perception of a more sympathetic ear in the White House, according to several people familiar with his thinking. On Sunday, Guatemalan soldiers beat back a caravan of thousands of Central Americans traveling north from Honduras and hoping to reach the United States.
Mexico, which mobilized extra security forces at its southern border to prepare for this latest caravan, is seen as crucial to holding off new waves of migrants. And with the pandemic still raging, the Biden administration will also need Mr. López Obrador’s cooperation in instituting more coronavirus testing and tracing for people who cross the southern border.
But Mr. Biden is unlikely to resort to threats or public humiliation to get Mexico to do what he wants — and that gives Mr. López Obrador an opening to try to set the tone for a more standoffish relationship early on.
While the Mexican president says he wants to maintain “a good neighbor policy” with the superpower at the border, he has also criticized his predecessors for being “servile and irresponsible in terms of enforcing our sovereignty.”
In the recent blowup over Mexico’s decision not to press charges against the former Mexican defense secretary, whom the United States accuses of working for a drug cartel, Mr. López Obrador defended himself by lashing out at American officials. He accused them of conducting “an investigation so irresponsibly and without evidence.”
His real goal, analysts say, may be to stoke the resentment of the Mexican public toward American intervention in the drug war.
“He’s trying to activate a certain anti-American streak,” said Carlos Bravo Regidor, a political analyst and associate professor at CIDE, a Mexican university. If he is successful, it may become easier to reject U.S. influence over his government.
“They are going to pressure López Obrador to change certain policies,” Mr. Bravo Regidor said, “and López Obrador is going say: ‘See? They’re trying to intervene in our internal affairs. And we’re not going to allow it.’”