Rising oil prices might cost you more money at the gas pump, but they're a boon for oil companies.
Crude oil climbed to its highest price since 2014 after President Trump vowed to pull out of the Iran nuclear deal. Iran is the world's fifth-largest oil producer, and American sanctions will choke off some of that supply.
The price of crude has been rising for more than two years, from $26 to $71 on Wednesday. That helps oil company profits, and Wall Street has jumped back on the energy bandwagon.
Energy stocks are up 12% in the past month, the best in the S&P 500. And they're up 5% for the year, while the broader market is flat.
Related: America's biggest oilfield is running out of pipeline
Oil and gas producers and refiners, including Andeavor (ANDV), Marathon Oil (MRO), Devon Energy (DVN) and Baker Hughes (BHGE), are among the biggest gainers in the S&P in the past month. Companies that support the drilling and transport of crude, such as equipment and service, have also benefited.
Exxon, which has been slow to capitalize on the shale revolution transforming the US oil industry, has ridden the rise in oil prices to a 7% gain over the past month. Chevron (CVX) is up 11%.
Energy companies almost doubled their first-quarter profit compared with a year ago, the best in the S&P, according to John Butters, senior earnings analyst at FactSet.
"Investors are feeling better about crude oil prices and the sustainability of prices," said Brian Kessens, portfolio manager at energy investment firm Tortoise. "They're taking a second look at the sector."
It's been a long road back for energy investors since oil crashed a few years ago.
Saudi Arabia-led OPEC launched a price war against the United States in 2015, ramping up production to cause a supply glut in the market. The move caused the price to fall from $100 to $26, and left the US industry reeling.
But prices slowly recovered. Shale output boomed in the United States, and Congress lifted a 40-year-ban on oil exports in 2016. OPEC and Russia, the world's largest producer, agreed to cut production. That eventually put a floor under global prices.
Recent uncertainty over the Iran deal, turmoil in Syria, and cutbacks in Venezuela have pushed prices up 17% since the start of this year.
Related: Venezuela's once-proud oil industry is collapsing
A healthy global economy is also propping up oil.
"The demand growth is soaking up the excess supply," said Dan Eberhart, CEO of oilfield services company Canary LLC. "People weren't expecting the demand growth to be so robust."
Memories of the downturn still weigh on investors. That kept a lid on energy stocks as recently as earlier this year, even as the price of oil rose. Investors feared surging US production would lead to another glut, but those concerns have eased.
Wall Street still has concerns. Investors worry that producers, which are pouring money into expensive projects, will be hurt if prices fall again.
This quarter, instead of spending even more, companies are returning some of their profit to shareholders. The industry has announced $9.4 billion worth of stock buybacks this quarter, compared with $1.8 billion a year ago, according to Howard Silverblatt, senior index analyst at S&P Dow Jones Indices.
"They're being disciplined," Kessens said. "They're not increasing their drilling budget just because crude oil prices are higher."
Analysts expect the energy rally to continue as long as oil prices remain in a so-called Goldilocks zone of $60 to $80 — not too low to create excess supply, not too high to curb demand.
OPEC and Russia are set to maintain their production cuts through the end of 2018, and Saudi Arabia wants to keep prices high to attract investors for its upcoming Aramco IPO. Both should limit a steep price drop.
— CNNMoney's Matt Egan contributed to this report.