Major stock indexes recovered early losses and closed sharply higher Wednesday, as investors bet the recent trade disruptions between the U.S. and China are negotiating tactics and the countries will ultimately reach a compromise.

Shares of manufacturers and machinery companies initially came under pressure after China unveiled plans for a series of retaliatory tariffs on American goods. But stocks erased those declines in afternoon trading, as some analysts said knee-jerk selling on worries that protectionist trade policies...