Shares of energy companies rallied alongside oil futures after an unexpected decline in inventories.

Oil futures topped $40 a barrel in New York after the Energy Information Administration released weekly inventory data showing the seventh drop in U.S. crude-oil stocks in eight weeks, bringing inventories to a five-month low.

Oil futures were also buoyed by signs that Hurricane Sally would weigh on oil production and processing in the Gulf of Mexico region for longer than anticipated.

Natural gas prices fell 4% lto $2.27 per million British thermal units, the lowest since Aug. 13 amid concerns that Hurricane Sally could reduce demand for natural gas due to power outages and the mild temperatures the storm is spreading across the southern U.S.

Write to Rob Curran at rob.curran@dowjones.com