LONDON — Prime Minister Boris Johnson of Britain, known for his bombast and outspokenness, began his first foreign trip as leader on Wednesday walking a daunting diplomatic tightrope, ostensibly trying to pry Brexit concessions from stony-faced Europeans while keeping a wary eye on his domestic opponents with a general election possible in the fall.

And looming over it all for the new prime minister is the vexing problem of President Trump.

Mr. Johnson, who spoke about Brexit with the German chancellor, Angela Merkel, in Berlin, on Wednesday, will also meet with the French president, Emmanuel Macron, in Paris on Thursday. But, while Mr. Johnson and Ms. Merkel both promised to try to work out a solution, the talks are not expected to break the deadlock that has poisoned and paralyzed British politics for three years.

Then it will be on to Biarritz, France, for a weekend meeting of the Group of 7 countries, where he will have to carefully calibrate his relationship with President Trump, an enthusiastic backer of Brexit who is deeply unpopular throughout the Continent and among Britons.

Mr. Johnson, who has stepped up preparations for the possibility of a potentially chaotic no-deal Brexit on Oct. 31, needs the president’s help if he is to strike a trade deal with the United States to cushion the economic impact. But he can ill afford to appear too chummy with him.