The new front line for Europe’s energy security is a modest office building overlooking a fjord in Stavanger, Norway. Inside, a company called Petoro oversees three dozen of the largest oil and natural gas fields in Europe, on Norway’s petroleum-rich continental shelf.

These operations — in Norwegian waters marked by massive offshore platforms and wells snaking thousands of feet below the surface — have been instrumental in helping Europe heat its homes and generate electricity since the onset of Russia’s war in Ukraine.

As Russia throttled back natural gas exports last year, Norway dialed them up, and it is now Europe’s main supplier of the fuel. Norway is also feeding greater quantities of oil to its neighbors, replacing embargoed Russian oil.

“The war and the whole energy situation has demonstrated that Norwegian energy is extremely important for Europe,” said Kristin Fejerskov Kragseth, the chief executive of Petoro, a state-owned company that manages Norway’s petroleum holdings. “We were always important,” she added, “but maybe we didn’t realize it.”

The significance of this elevated status is not lost on Norway, a nation of 5.5 million people, where energy represents about a third of economic output and where, not unlike Saudi Arabia, the government owns not only the oil and gas fields but also large stakes in companies extracting them. By increasing demand for this energy, the war in Ukraine has helped add about $100 billion to Norway’s oil and gas earnings.

Many in Norway have mixed feelings about this reliance on fossil fuels, and tensions over climate change and further exploring for petroleum dominated the last national election, in 2021. But the sudden importance of energy supplies appears to have given rise to a consensus that the country should continue, at least for a few years, producing robust amounts of petroleum.

The war “has changed the political sentiment,” said Ulf Sverdrup, the director of the Norwegian Institute of International Affairs, a research organization. “Basically, Europe said: ‘Hey! We need your energy.’”

A small country with a border with Russia, Norway is not a member of the European Union, but it listens closely to its neighbors. After the war started, Brussels and European nations, especially Germany, which had depended heavily on Russian gas, leaned on Oslo for help.

“Norway’s contribution to Europe has been to uphold gas exports and to increase them,” Jonas Gahr Store, Norway’s prime minister, said in an interview.

Norway was already producing a high volume of gas, shipping it through undersea pipelines to northern Europe, but the government authorized additional output. Energy companies made adjustments that increased gas production at the expense of oil. The result was an 8 percent increase in gas production last year, which made Norway the source of about one-third of the gas consumed in Europe.

“We really kind of stepped up in terms of turning every stone,” said Anders Opedal, the chief executive of Equinor, Norway’s state-controlled energy producer.

Norway has reaped handsome financial rewards for coming to Europe’s aid. Just as energy companies like Shell and BP pulled in record profits last year, Petoro earned about $50 billion in 2022, almost three times what it made in 2021, and Equinor reported record adjusted earnings of $75 billion. Revenues from oil and gas contributed $125 billion to the Norwegian state in 2022, according to government estimates — about $100 billion more than in 2021.

That money flows into a $1.3 trillion sovereign wealth fund formally called the Government Pension Fund Global but known to many as the oil fund. It holds, on average, 1.5 percent of 9,000 listed companies worldwide, and the government can tap its expected annual earnings to finance almost 20 percent of the state budget. This arrangement helps shield the Norwegian economy, which grew 3.3 percent in 2022, from the ups and downs of oil and gas prices.

But whether the Norwegian industry’s bumper profits will continue is another question. European gas prices have been falling for months, and are now around one-eighth of the peak they hit last summer. And the war may actually accelerate the continent’s shift from gas to renewable energy that was underway before the invasion.

The riches earned since the fighting started have angered some Norwegians. “We consider that profit as war profits,” said Rasmus Hansson, a member of Parliament from the Green Party. He suggested that the money should be invested in a fund to aid Ukraine and other countries affected by the war.

Producing oil and gas, as well as large amounts of hydropower, did not protect Norwegians from the soaring electric costs that hit most Europeans last year, because its markets are closely linked to its neighbors’.

“It was four times as expensive as a normal year,” said Svein W. Kristiansen, an owner of Smed T. Kristiansen, a family firm in Stavanger that makes parts for oil installations and offshore wind farms.

Norway should be able to maintain its high gas flows to Europe in the coming years. In 2020, the government put into effect temporary tax changes to ensure that the pandemic did not halt investment in the industry. These incentives have led to a burst of new drilling and development, worth an estimated $43 billion.

An oil and gas company based outside Oslo, Aker BP, plans to invest $19 billion to increase output by a third by 2028. “We are drilling exploration wells all the time,” said Karl Johnny Hersvik, the chief executive.

Over the next few years, output from these new fields should be enough to offset the declines from older ones, according to Mathias Schioldborg, an analyst at Rystad Energy, a Norwegian-based consulting firm. Scenarios modeled by the government show oil and gas output in Norway reaching a peak toward the end of this decade, followed by a long decline.

It is doubtful, though, that Norway can supply significantly more gas to Europe. The network of pipelines feeding Norwegian gas to the continent has little additional capacity.

“We are running as much as we can and as hard as we can,” Mr. Hersvik said. The case for building additional pipelines to Europe is weak, he said, because around 20 years of operation would be needed to recoup the investment cost. “I sincerely hope we have solved this problem before that,” he said, referring to the war in Ukraine.

Pressures for Norway to reduce its greenhouse gas emissions and curb the oil and gas industry are not likely to go away. Mr. Hansson, the Green Party legislator, said he thought Norway should phase out fossil fuels by around 2035 to safeguard the climate.

Environmental groups concede that natural gas production is needed because of the war, but they say the government should not use the energy crunch as leverage to develop new oil and gas fields that would produce fossil fuels for many years.

“Norway is locking Europe into what is really a problem for the climate,” said Frode Pleym, the head of Greenpeace in Norway.

Like most European countries, Norway has begun a transition to cleaner energy. The oil and gas industry is investing in offshore wind farms and seeking to cut emissions from oil and gas production by powering pumps and other gear with electricity instead of gas or diesel.

But this transition worries some people in the industry who suspect that renewable technologies won’t generate enough well-paid jobs to sustain the roughly 6 percent of the labor force now working in oil and gas.

Hilde-Marit Rysst, the leader of SAFE, a union that represents 12,000 energy workers, said working on petroleum platforms was more stimulating and rewarding than the work available in the renewable energy industry.

“You use your brain, your education and your experience,” she said. “It doesn’t look like you are going to get that from wind turbines.”

Stavanger, a pretty city with old wooden houses built around the fjord, has been Norway’s oil and gas hub for 50 years. It has been hit by job losses in last decade — first from the collapse of oil prices in 2014 and then from the pandemic — but new investments have reinvigorated the city.

Its mayor, Kari Nessa Nordtun, seems prepared to embrace whatever comes along. “I am a proud oil kid,” Ms. Nordtun said, but she also applauded companies that once focused on the oil business for “putting money and people into renewables.”

Still, there are nearly 50,000 jobs in the Stavanger region related to oil and gas compared with around 1,000 in green energy.

Analysts say the Norwegian government is pragmatic and likely to shape the country’s energy industry so that it stays in line with the energy policies of the European Union and the demand of European neighbors like Germany.

“For Norway to have a future,” said Mr. Sverdrup, the director of the Norwegian Institute for International Affairs, “we have to be aligned to the future energy system in Europe.”

Henrik Pryser Libell contributed reporting from Oslo, and Erika Solomon from Berlin.