“Connecting U.S. oil production to global markets will have immediate national security impacts,” said David Goldwyn, who was the top energy diplomat in the State Department during the first Obama administration, “and as the market recovers it will enable struggling American companies to meet rising demand.

Environmentalists have long opposed the change in policy, contending it will encourage more drilling and production when they say the world should be shifting to renewable energy. They say more oil production means more hydraulic fracturing, air pollution and threats to local water supplies. That is why Democratic lawmakers insisted that the repeal be accompanied by an extension of tax credits for wind and solar energy.

The promise of those extensions — along with those aimed at promoting the development of biofuels, especially those derived from nonfood sources — prompted a collective sigh of relief among clean energy executives and investors.

Stock prices, which had tumbled in recent months in the face of volatility in the sector, rallied. SolarCity, for example, was up about 30 percent to around $52 in the afternoon, practically double where it was a month ago, while SunEdison, whose stock has languished below $10 since September, had climbed roughly 30 percent to above $6.

The production tax credit for wind, which had expired at the end of 2014 and helped bring the cost of wind power near or below that of conventional fuels in many parts of the country, is to be extended retroactively until the end of next year and then decline in value each year until it is phased out in 2020. The investment tax credit for solar, which was to decrease to 10 percent, from 30 percent, at the end of next year, is to stay at 30 percent until 2019 and then gradually step down until 2022.

Energy policy experts said that the agreement allowed Republicans and Democrats to claim victory, but was also a sign that the transition to a lower-carbon economy promised in the Paris climate talks was already an industry reality.