WASHINGTON—Even for a presidency defined by stark contrasts, President Trump’s week was one of political whiplash, bouncing from legislative successes to a historic rebuke.

The president clinched congressional Democratic support for his new North American trade deal, won backing for the creation of the U.S. Space Force and reached a limited trade deal with China.

But...