OPEC and its Russia-led oil-producing allies agreed to unleash millions of barrels of bottled-up crude over the next two years, committing to restore all the cuts they made at the start of the Covid-19 pandemic as many economies pick up and crude demand recovers.

Underscoring the uncertain speed of a full economic recovery and a return of pre-pandemic oil demand, the group chose to move gradually, agreeing to modest, monthly installments of new oil through the latter end of 2022. Oil prices have eased recently in anticipation of a deal, but analysts said the gradual nature of the output boost could continue to pressure prices.

The prospect of an OPEC deal had already led to a drop in prices, which have recovered strongly this year. Brent, the international benchmark, and West Texas Intermediate have both fallen about 5% in recent days, as hope grew for an OPEC deal. Brent closed above $73 a barrel, and WTI finished above $71 a barrel Friday, both off recent, multiyear highs.

The move also demonstrates the world’s push-pull over its reliance on fossils fuels. Europe and the U.S. have pushed ambitious plans to wean themselves from carbon-emitting fuels like oil. But the world is still largely dependent on plentiful supplies of such fuels, including oil.

The Biden administration, while pushing for an energy transition to greener fuels, reached out to Saudi Arabia and the United Arab Emirates when those two OPEC members clashed over terms of a deal. U.S. gasoline prices have risen this summer, a consequence of higher oil prices.

The output hike will “please the White House, which has worried … about the impact of higher gasoline prices on U.S. consumers,” said Helima Croft, the chief commodities strategist at Canadian broker RBC.

Sunday’s oil deal calls for the Organization of the Petroleum Exporting Countries and a Russia-led group of big producers to raise production by 400,000 barrels a day each month through the end of 2022. The deal seeks to unwind all the cuts the two groups, collectively called OPEC+, agreed to make at the start of the pandemic.

The deal marks a turning point for the oil industry, which went into a tailspin in the early months of the pandemic. Economies around the world went into hibernation, and oil demand sank. At one point, oil markets were so chaotic that futures for U.S. benchmark crude briefly fell below zero. Oil-storage facilities were brimming full, and producers, trader and buyers were storing oil at sea because they had no need for it.

Big producers retrenched, cutting spending and jobs and seeking to sell assets to pare debt.

By contrast more recently, oil prices have been rallying most of the year on returning demand, particularly in rich countries. Oil companies have returned to profitability, and shares have risen sharply.

But the demand outlook remains uncertain. Much of the developing world, where demand growth for oil had been strongest pre-pandemic, is still fighting surging Covid-19 cases. Powerhouses such as India and Indonesia have been ravished by the so-called Delta variant of Covid-19. Even in China, which appeared to be recovering strongly from pandemic-inspired economic shutdowns, economic data has been uneven.

In the developed world, meanwhile, soaring demand has triggered price increases, shortages and supply bottlenecks for all sorts of goods. Analysts are forecasting stronger oil demand in the short term from economies whose pre-pandemic thirst for crude was largely flat.

Still, the Delta variant has boosted infection in the U.S. and Europe, too, casting a cloud of uncertainty over the pace of recovery in those places. Governments are betting their vaccination drives will keep a lid on hospitalizations and deaths, while allowing the continuance of new freedoms, such as open restaurants, unrestricted travel and large gatherings.

OPEC expects oil demand in industrialized nations to increase by 2.7 million barrels a day in 2021, up 6.3%. More than half of that growth will come from the U.S., at 1.5 million barrels a day, it said. In its first 2022 forecasts for the global oil market, OPEC said last week it expected the world’s appetite for crude to rise by 3.3 million barrels a day to average 99.9 million barrels a day next year. That is about the level of demand pre-pandemic.

In its deal Sunday, OPEC+ committed to meeting most of that with oil it had previously taken off the table. The only other producer capable of quickly ramping up output is the U.S., but the smaller shale-oil players there have been mostly on the sidelines amid this year’s dramatic recovery in oil prices. They have been able to raise money from investors, but have plowed that into paying down debt.

The deal also could re-establish OPEC+’s credibility in the markets, signaling a more disciplined approach. Through much of the year, the group has swung widely between optimism and pessimism about demand growth. Saudi Arabia has tended to be more cautious. Russia, by contrast, has sought to boost output. More recently, the public spat over production levels between Saudi Arabia and the U.A.E. delayed consensus and threatened a more serious splintering of the group. In such a scenario, members could have simply opened up their spigots, flooding markets.

The deal is “good for consumers in the short term,” said Robin Mills, chief executive of Dubai-based consulting firm Qamar Energy, though he and other analysts expect price pressure to remain as demand builds. “The market will be tight this summer,” said Giovanni Staunovo, a commodity analyst at Swiss bank UBS.

The group said it would reassess market conditions in December. The deal goes into effect next month.

Early last year, OPEC+ slashed 9.7 million barrels a day of its collective output, equivalent to about 10% of 2019 demand. It has restored about 4 million barrels of that.

The deal is broadly in line with one struck earlier this month. Final agreement had been held up for over two weeks after the U.A.E. asked for its production quota inside the group to be reassessed. It was eager to pump more crude than its allotment, after investing heavily in its oil fields.

Saudi Arabia, OPEC’s de facto leader, reached a compromise with the U.A.E. last week, agreeing to eventually boost that quota.

On Sunday, the group also decided to boost other members’ baselines, the estimate of the maximum amount of oil each country is capable of producing. The adjustments go into effect in May 2022. Those technical adjustments would also boost affected countries’ real output since that is based on the baselines.

OPEC said the U.A.E.’s baseline would go up by about 332,000 barrels a day. Saudi Arabia and Russia will each get their baseline lifted by 500,000 barrels a day. Overall, the group’s estimated production capacity is being upgraded by 1.63 million barrels a day.

The compromise between Saudi Arabia and the U.A.E. patched up for now the clash between two of OPEC’s closest traditional allies. While Saudi Arabia is far and away the bigger producer and regional power, the U.A.E. is one of just a few OPEC members with so-called spare capacity—barrels it can turn on and off quickly.

Write to Benoit Faucon at benoit.faucon@wsj.com and Summer Said at summer.said@wsj.com