Gasoline futures rallied Thursday by more than 5%, providing a lift to oil prices following a two-session decline, as the shutdown of a key pipeline looked set to stretch into a full week.

The temporary closure of the Colonial Pipeline Line 1, which transports 1.2 million barrels of gasoline a day from Texas as far as New Jersey, began last Friday because of a leak. The pipeline has spilled about 6,000 barrels of gasoline, according to Colonial Pipeline. The company, however, said it “does not expect disruptions to be long term” and could restart the line this weekend.

October West Texas Intermediate crude CLV26, rose 33 cents, or 0.8%, to settle at $43.91 a barrel on the New York Mercantile Exchange after tallying a loss of nearly 6% in the past two sessions. November Brent UK:LCOX6 on the ICE Futures exchange in London added 74 cents, or 1.6%, to $46.59 a barrel.

“The Colonial Pipeline issues have resulted in the premium for products today, while crude really seems to be guided by the crack spread,” said Robbie Fraser, commodity analyst at Schneider Electric, referring to the price difference between crude oil and the petroleum products extracted from it.

On Nymex, October gasoline futures US:RBV6 rallied by 6.9 cents, or 5.1%, to finish at $1.430 a gallon. The settlement was the highest in over three weeks. October heating oil US:HOV6 added 3.5 cents, or 2.5%, to $1.416 a gallon.

“We’re seeing a strong boost to product contracts through the end of the year and beyond, and that lifts the crack spread for refiners,” said Fraser. “As a result, the wider the spread gets, the more tempting it is to buy crude and sell products, meaning that an initial sharp rise in products has to eventually pull crude along for the ride.”

“Add that to lingering questions over whether the market effectively priced in [Wednesday’s] bullish crude inventory number, and we end up with today’s move higher,” he said. U.S. crude-oil supplies unexpectedly fell by 600,000 barrels for the week ended Sept. 9.

Read:Here’s why 31 million barrels are set to disappear from U.S. oil inventories

As for the impact of the gasoline pipeline shutdown, Patrick DeHaan, senior petroleum analyst at GasBuddy.com, told MarketWatch that “while it causes shortages on the East, it’s backing up material in the Gulf.”

So the gasoline pipeline shutdown may cause some areas of the South and mid-Atlantic to see “incremental increases in the next few days of a penny or two a day” in retail gasoline prices. “Nothing to get overly concerned about yet—but it’ll depend on how quickly Line 1 can be restarted.”

Early Thursday, oil prices were pressured by some strength in the dollar and expectations for higher global production, as downbeat U.S. economic data spurred concerns over the prospects for energy demand.

Data on August U.S. industrial production showed a decline of 0.4%, after a revised 0.6% rise in July. Earlier Thursday, separate data showed that retail sales fell in August for the first time in five months. Weak economic data suggests the possibility for a decline in demand for energy.

The market also remains jittery after a series of bearish reports from the Organization of the Petroleum Exporting Countries, the Paris-based International Energy Agency and the U.S. Energy Information Administration this week.

All three confirmed the continuing oversupply of crude that has engulfed the market and kept prices low over the last 2½ years.

Where to find 5% yields...and 12% ones

Meanwhile, news that Nigeria and Libya are now in a position to ramp up oil exports may offer a headwind for oil.

Royal Dutch Shell PLC RDSB, +3.16% and Exxon Mobil Corp. XOM, -2.47% have both lifted force majeures on Nigerian exports after militants had caused the shut-in of supply. Libya is also planning to resume exports from its Ras Lanuf port and a tanker is now due to be loaded with 600,000 barrels of crude.

“Nigeria’s problems are clearing and along with Libya, this could mean 1 million b/d of crude entering the market,” Olivier Jakob of Switzerland’s Petromatrix said.

In the natural-gas market, prices climbed as a weekly report showed that U.S. supplies of the commodity rose in line with market expectations.

Th EIA said Thursday that natural-gas supplies rose 62 billion cubic feet for the week ended Sept. 9. Analysts polled by S&P Global Platts forecast an increase of 59 billion to 63 billion cubic feet.

October natural gas US:NGV16 rose 3.8 cents, or 1.3%, to $2.927 per million British thermal units.

— Carla Mozee in London contributed to this article.