The US president pushed Canada and Mexico to the edge of a trade war and pulled back at the last moment.