Markets concluded tariffs on Mexico and Canada would hurt the economy and raise prices. But they got both countries to act.