The U.S. and Canada reached a dramatic, last-minute deal late Sunday night on revising the North American Free Trade Agreement, lifting a cloud of uncertainty over the quarter-century-old continental commercial bloc.

The pending agreement will allow Canada to join an accord reached in late August between the U.S. and Mexico and diminishes the prospects for President Trump to follow through on his threats either to kill Nafta outright or to break the trilateral pact into separate pieces.

The...