Oil prices were going down again. Then war started in the Middle East.

The price of oil went up as much as 5% as fighting escalated between Israel and Hamas.

Houston • After a surge this summer when oil prices approached $100 a barrel, the cost of crude was tumbling again. Now a Middle East war has sent it right back up.

Traders drove up the price of oil as much as 5% as fighting escalated between Israel and Hamas after the terrorist group attacked the Jewish state from the Gaza Strip over the weekend.

No oil is produced in the Gaza area, and Israel produces only a small amount of oil for its own use, energy analysts noted. But experts warned that prices could go higher if the fighting were to spread around the region, especially if Iran becomes actively involved in the war.

“Any expansion of battles will have potential repercussions on oil markets,” according to a note released Sunday by Citi investment research.

Energy prices had been slumping over the past week in part because of recent unexpectedly strong growth in the output of oil from several countries, including some in OPEC, the oil cartel. Two main reasons were that economic growth in China remains weak, and high interest rates have spurred concerns over growth in Europe and the United States.

The average price for a gallon of regular gasoline in the United States on Monday was $3.70, 11 cents lower than a week ago, according to the AAA motor club.

But that relief for drivers is now in jeopardy following a stunning geopolitical event, much as Russia’s invasion of Ukraine sent oil and natural gas prices skyward last year.

“War in the Middle East can be generically bullish for crude,” said Clearview Energy Partners, an analytics firm, in a research note Sunday night, especially if the conflict is prolonged.

Global oil bench marks rose a little over 5% when markets opened after the weekend, with the West Texas Intermediate oil price rising to $87 a barrel, a relatively modest jump when war is breaking out in the oil-rich Middle East. The increase followed several days when prices slumped, bottoming out near $82 a barrel, on the expectation that demand for oil was waning. The inventories of American gasoline climbed last week to above the five-year average for this time of year. Only two weeks ago, many analysts were predicting a surge to $100 a barrel.

Prices moderated later Monday, in a choppy trade, with crude about 4% higher.

One reason oil prices had softened in recent days was growing speculation that Saudi Arabia, the United States and Israel were closing in on a political deal that could lead to an eventual Saudi recognition of Israel. There were hopes that Saudi Arabia might increase oil output to cut gasoline prices to help the Biden administration sell any deal to the U.S. Congress.

Saudi Arabia has insisted that Israel make major concessions to the Palestinians, but the conflict is likely to complicate the chances of any deal between Israel and Saudi Arabia.

Even though American, Canadian, Brazil and Guyanese oil production has ramped up in recent years, the Persian Gulf remains a key source and transit point for nearly 1 in every 5 barrels of global oil supplies, especially to Asia. Iran is still one of the biggest oil producers in the Middle East, despite Western sanctions in recent years.

Any indications that Hamas attacked Israel following prodding, financing and planning by Iran could escalate the conflict beyond Israel’s borders.

The Biden administration has softened sanctions on Iran in recent months, in part to encourage Iran to slow its nuclear program, allowing the country to export more oil into tight global markets. But pressure is likely to grow now to tighten sanctions again, as the Biden administration provides more aid to Israel.

This article originally appeared in The New York Times.