With Mr. Trump’s re-election campaign approaching, he and his advisers are increasingly conscious of the need to limit any economic damage, particularly among key political constituencies like farmers, who have suffered the most.

The American farm economy has stumbled into recession, hurt by a sharp drop-off in sales to China, among the largest export markets for agricultural goods like soybeans, pork and corn. While the administration has tried to blunt the pain with two rounds of financial assistance, farmers have increasingly pleaded with the White House to end the trade war, saying the handouts are not enough to make up for the lost sales.

That pain was set to get worse next week. Until Friday’s truce, Mr. Trump had planned to increase tariffs on $250 billion worth of goods to 30 percent from 25 percent, a hike that would likely have been met with further retaliation by China and been particularly burdensome for consumers and businesses going into the holiday season.

Mr. Trump said on Friday that China has agreed to buy $40 billion to $50 billion worth of American farm goods annually, after scaling up over a period of two years. He compared the figures to annual Chinese purchases before the trade war, which were about $24 billion.

“The deal I just made with China is, by far, the greatest and biggest deal ever made for our Great Patriot Farmers in the history of our Country,” Mr. Trump tweeted on Saturday morning. “In fact, there is a question as to whether or not this much product can be produced? Our farmers will figure it out. Thank you China!”

The compromise is even more timely for Mr. Xi. Sharply rising food prices have become a national issue in China. A lethal epidemic among the country’s pigs, with mortality as high as what people in Europe faced during the Black Death of the mid-14th century, has sent prices skyward for pork as well as for alternatives like beef and lamb.

As the Chinese public has begun asking, “Where’s the beef?”, China’s trade negotiators suddenly have an answer: It can come from the United States, along with a lot of pork, soybeans and other food.