Stock markets around the globe posted their first weekly gains in a month as the price of oil climbed back above $32 a barrel.

After weeks of steep losses, investors waded back into the market in the second half of the week. The hardest-hit areas of the stock market in 2016, including energy producers and some technology companies, made some of the sharpest gains.

The...