WASHINGTON — President Trump agreed on Friday to lift tariffs on metal imports from Mexico and Canada, removing a major irritant for two important allies that in exchange agreed to stop punishing American farmers with their own taxes on pork, cheese and milk.

At the same time, Mr. Trump postponed a decision on whether to impose tariffs on automobiles imported from Europe, Japan and other countries for six months, setting a tight deadline for the United States to reach trade deals that have so far proved elusive.

Together, the actions remove the threat of an all-encompassing global trade war and allow Mr. Trump to focus on pushing China to agree to the United States’ trade terms, as well as pressuring Europe and Japan to reach a trade deal before the 2020 election. His trade war has hurt many of the farmers who make up his political base, and he is eager to make good on a 2016 campaign promise to rewrite trade deals in America’s favor.

“I’m pleased to announce we’ve just reached agreement with Canada and Mexico. We’ll be selling our product into those countries without the imposition of tariffs,” Mr. Trump said on Friday.