Oil prices surged more than 9% Wednesday, as investors hoped a deal clinched by major oil-producing nations would help oil prices break out from a punishing slump that has lasted more than two years.

After weeks of doubt that members of the Organization of the Petroleum Exporting Countries could resolve their differences, the agreement in Vienna on Wednesday seemed to surprise many investors. The percentage gains were the biggest for U.S. and international crude prices since February, jolting a market toward the top of a...