But the full accounts of the conversations illustrated Mr. Trump’s approach with foreign leaders — flattering his counterpart one moment, badgering him the next, always conscious of how the policies being discussed connected to his campaign promises and how they would affect his domestic political standing.

Fresh from his inauguration, he had his campaign victory on his mind, boasting to Mr. Peña Nieto that “no one got people in the rallies as big as I did” and to Mr. Turnbull that “they said I had no way to get to 270” votes in the Electoral College “and I got 306.” He buttered up Mr. Peña Nieto, telling the interpreter on their call that “he speaks better English than me,” suggesting that the Mexican president would be so popular that the Mexican people will amend their constitution to allow him to run again and declaring that “it is you and I against the world, Enrique, do not forget.”

But there was an edge to both conversations as he sought to bring his campaign platform to fruition. The talk with Mr. Peña Nieto on Jan. 27 came after the Mexican leader canceled a meeting with Mr. Trump because of their dispute over who would pay for the proposed border wall. The two never resolved that on the call, with both men clearly worried about the political effect in their own countries.

“We find this completely unacceptable for Mexicans to pay for the wall that you are thinking of building,” Mr. Peña Nieto told Mr. Trump, explaining how precarious his position was at home. “I would also like to make you understand, President Trump, the lack of margin I have as president of Mexico to accept this situation.”

Mr. Trump too was conscious of his own position: “On the wall, you and I both have political problem. My people stand up and say, ‘Mexico will pay for the wall,’ and your people probably say something in a similar but slightly different language. But the fact is we are both in a little bit of a political bind because I have to have Mexico pay for the wall. I have to. I have been talking about it for a two-year period.”

Mr. Trump suggested papering over the dispute in public comments: “We should both say, ‘We will work it out.’ It will work out in the formula somehow. As opposed to you saying, ‘We will not pay’ and me saying, ‘We will not pay.’”