MEXICO CITY — For more than two years, Donald J. Trump has attacked Mexico to excite his political base, threatening walls, mass deportations and an end to a nearly 25-year free trade deal between Mexico and the United States.

As frequent targets of Mr. Trump’s ire, many Mexicans have learned to take it in stride, finding that the bark is often worse than the bite.

On Thursday, however, the Trump administration clamped down on Mexico’s steel industry, along with those of Europe and Canada, imposing a 25 percent tariff on Mexican steel imports — the first real attack on the $1.5 billion in trade that crosses the border both ways every day.

Almost immediately, Mexico responded with a round of countertariffs, retaliations aimed straight at the heart of Mr. Trump’s base of political support. The reprisal had been drawn up for some time, in anticipation of the tariffs, which were first announced in March and delayed until now.