Mexico is Washington’s largest trading partner, sending across the border items like tomatoes, cars and rugs. Mexico sent the United States $346.5 billion of goods last year — meaning that a 5 percent tariff on those products would amount to a tax increase of more than $17 billion.

Most of the costs would then be passed on to businesses and consumers.

Mexico’s deputy foreign minister for North America, Jesús Seade, said at a hastily arranged news conference on Thursday that Mr. Trump’s announced tariffs would be “disastrous” and suggested Mexico could retaliate against American products. But in a letter to Mr. Trump posted online, President Andrés Manuel López Obrador of Mexico said he did not want a “confrontation” with his American counterpart and insisted on the need for dialogue.

Mr. Trump’s frustration over the rising number of illegal border crossings has steadily risen since January, when Democrats refused to grant him billions of dollars to build his long-promised wall along the southwestern border. Since then, he has consistently framed immigration as a national security crisis and tried different tactics to punish the countries he blames for the flow of migrants.

[Read on how China is planning a list of US firms to block in answer to Trump.]

He has moved to cut off all foreign aid to countries like Guatemala, Honduras and El Salvador, and threatened to completely seal off the border with Mexico, a move that numerous officials told him would violate American law and international treaties.

He later retreated from that threat by giving Mexico a “one-year warning” instead and threatening heavy auto tariffs on cars coming into the United States. Mr. Trump also shifted hundreds of Customs and Border Protection agents from inspecting goods flowing into the United States to policing the southwestern border, a move that has disrupted trade by producing long wait times at border crossings.

He has also purged top officials at the Department of Homeland Security, including the secretary, Kirstjen M. Nielsen. But he has continued to say that he believes Mexico could do more to prevent the problem.

Earlier on Thursday, the administration said it planned to seek congressional approval of its revised trade pact with Mexico and Canada, known as the United States-Mexico-Canada Agreement, which would preserve the ultralow tariffs originally put into place under Nafta. To hasten approval of the deal in all three countries, Mr. Trump recently agreed to lift tariffs the United States had placed on steel and aluminum imports from Canada and Mexico. Those countries, in turn, agreed to lift punishing tariffs on American goods, including farm products like pork, whiskey, apples and cheese.