Both sides said a possible meeting between the two presidents remained on the table, though not on the timeline or in the style that had been planned.

The confrontation, according to a Mexican official, chilled the warmth and good will that had been built up between the two sides over months of negotiations, and sapped whatever level of trust had been developed after a difficult start to the relationship.

It was not the first time that a disagreement over the wall spoiled the chance for the two presidents to establish a rapport.

In another testy call shortly after Mr. Trump was inaugurated last year, the president pressed Mr. Peña Nieto to stop saying publicly that he would not pay for the wall, saying that would be a precondition for future talks.

“If you are going to say that Mexico is not going to pay for the wall, then I do not want to meet with you guys anymore because I cannot live with that,” Mr. Trump said, according to a transcript of that call obtained by The Post and posted online last summer.

Mr. Peña Nieto told Mr. Trump during that call that the notion of Mexico paying for the wall was “completely unacceptable for Mexicans,” saying it would also be politically toxic for him to ever accept it. But Mr. Trump told Mr. Peña Nieto that he regarded his vow that Mexico would pay for the wall as a political imperative that he dared not relinquish.

The issue derailed the first attempt by the American and Mexican governments to coordinate a meeting between the two presidents. During a January 2017 visit to Washington by Foreign Minister Luis Videgaray to arrange an announced visit, Mr. Trump took to Twitter to complain that Mexico seemed unwilling to pay for the border wall. Mr. Videgaray suspended all of his meetings and returned home. It was clear to Mexican officials then that there would be no benefit to Mr. Peña Nieto in meeting with Mr. Trump.