Mexican officials have been negotiating for months in hopes of reaching a trade deal with Washington that would not devastate the countrys export-driven economy, but President Trump upended those talks on Saturday when he threatened to impose a 30 percent tariff on Mexican imports, potentially igniting a trade war with one of Americas largest trading partners.

In a letter to Mexicos president, Claudia Sheinbaum, Mr. Trump said that Mexico was not doing enough to curb the flow of fentanyl into the United States and cited that as the reason for the tariffs. Mr. Trump added that Mexican companies were welcome to manufacture their products in the United States to avoid the tariffs.

The tariffs are set to take effect on Aug. 1 and are similar to the levies that the United States is imposing on imports from Canada and the European Union, which Mr. Trump said separately on Saturday would also face 30 percent duties. The tariffs come despite the fact that Mr. Trump brokered a trade deal with Mexico and Canada during his first term that was intended to stabilize economic relations between the United States and its neighbors.

Mr. Trump also warned Mexico not to retaliate with higher tariffs of its own. He said that whatever additional tariffs Mexico might impose would be added to the 30 percent rate he announced.

The president added that drugs were not the only issue of concern to the United States and pointed to other Mexican policies that contributed to unsustainable trade deficits.

The Trade Deficit is a major threat to our Economy and, indeed, our National Security! Mr. Trump wrote in the letter.

Subscribe to The Times to read as many articles as you like.