The Organization of Petroleum Exporting Countries agreed today to cut its official price by $5 a barrel to $29, the first such reduction in the group's history, in an effort to curb the steep decline in its share of the global energy market.

After 12 days of intensive negotiations, OPEC oil ministers also set a ceiling for their combined output at 17.5 million barrels a day, just over half of what OPEC was producing at its last peak in 1979. They agreed on individual output quotas for 12 of the cartel's 13 members, leaving Saudi Arabia as a "swing producer" to adjust its production to support the new price.

The 15 percent OPEC price cut theoretically translates into savings of about 12.5 cents a gallon for gasoline and heating oil in the United States, according to a generally accepted formula saying that prices drop 2.5 cents a gallon for each $1-a-barrel fall in crude prices.

Most analysts agree, however, that the effect will be much smaller, leading only to cuts of a few pennies a gallon at most. That is true primarily because U.S. oil companies already have lowered prices in anticipation of an OPEC price cut. In addition, the federal gasoline tax is scheduled to be raised by 5 cents a gallon on April 1.

In reaching the compromise despite major differences among its members, the once-powerful cartel avoided its own collapse and prevented, at least for now, a free fall in oil prices. Meetings in December and January had failed, and this session seemed deadlocked at times.

Saudi Arabian Oil Minister Ahmed Zaki Yamani, representing OPEC's leading producer, told reporters tonight that he was "very satisfied" with the accord. "I have a strong feeling," he said, "that this will work out . . . . OPEC will be in the driver's seat."

But it remains in doubt whether the agreement will restore what OPEC's communique called "oil market stability," according to oil industry analysts. Open-market oil prices have been running as much as several dollars below even the new OPEC price, and current OPEC output is only 13.9 million barrels per day, the newsletter Petroleum Intelligence Weekly said today.

This puts OPEC's share of the world oil market at only about 38 percent, a drop of one-fifth in just the past three months, according to the Paris-based International Energy Agency. The key question, analysts said, is whether the price announced today is low enough to attract buyers as the world emerges from a prolonged recession in the coming months.

Much will depend on whether OPEC's members abide by the agreement and end the widespread discounting of the past year, when at least half the countries sold at prices below the old official price of $34. In a series of press conferences, ministers maintained that the protracted bargaining of the London talks--by far the longest OPEC meeting ever--showed that the members intend to take the outcome seriously.

The communique specifically asserts that "members shall avoid giving discounts in any form whatsoever." Yamani, who has consistently expressed optimism that differences would be overcome because the survival of OPEC was at stake, said that he has "strong hopes, strong indications that this time everybody means business."

Iran, which is at war with fellow OPEC member Iraq, has been the most persistent of the undercutters, selling its oil for as much as $8 a barrel below the official price. The communique said that Iran "reserved its position" on the price, but OPEC sources said that Iranian Oil Minister Mohammed Gharazi privately had backed it.

Iran's position was that OPEC's official price could be kept high by slashing the combined output level to no more than 14 million barrels a day, with Saudi Arabia--which supports Iraq in the conflict--making the biggest reductions. This problem finally was overcome when the Saudis agreed to raise or lower production depending on market demands.

At present, Yamani disclosed, the Saudis are producing only 3.5 million barrels, compared with more than 10 million barrels in the summer of 1981. Under the new overall ceiling, assuming that other members produce at their ceiling levels, the Saudis can pump a maximum of 5 million barrels and will remain the organization's largest producer.

In Washington, Treasury Secretary Donald T. Regan said that the OPEC price cut was "clearly good news for the U.S. and for the world economy. It will mean less inflation and will serve as a strong shot in the arm to the budding economic recovery.

"The oil price reduction will obviously place some strains on certain oil exporters with large external debts," he continued. "However, of the 10 nations with the largest debts, eight are oil importers. This action will be of great benefit to them."

Regan added that "it will be interesting" to see if the OPEC production ceilings will be "sufficient" to prop up prices.

The individual production quotas were the most difficult issue, ministers said. The last stumbling block was Venezuela, which has a massive foreign debt and sought to increase its quota. Venezuela's oil minister, Humberto Calderon Berti, agreed to a compromise figure of about 1.7 million barrels, which represents a modest increase.

The other quotas, while not officially announced, were listed for reporters by Kuwaiti Oil Minister Ali Khalifa Sabah. The Iranian quota was doubled from its level a year ago to 2.4 million barrels a day, reflecting Iran's success in boosting its production by undercutting prices. Five other countries received modest increases that effectively were at the expense of the Saudis, who had a ceiling of 7.65 million barrels a day under the March 1982 agreement.

OPEC's success in maintaining its new price structure for oil will depend in part on policies of such major non-OPEC producers as Mexico and Britain. Mexico, which like Venezuela has a large foreign debt, sent a senior official here to monitor the talks. The Mexicans later today announced cuts of between $2 and $3.50 a barrel to bring their oil in line with OPEC prices.

Britain's position is more complicated. Despite repeated appeals for cooperation from OPEC ministers, the Conservative government here has said that the price for Britain's North Sea oil would be set strictly by market forces.

Last month, the state-owned British National Oil Co. cut its price by $3 a barrel to $30.50. In response, OPEC member Nigeria--whose high-quality light oil competes directly with similar British crude--cut its price to $30. That move, raising the specter of an uncontrolled price war, prompted the marathon talks that ended today.

In the agreement, Nigeria was permitted to maintain its new price. The oil companies that buy British oil thus are expected to seek a further cut from the British oil company in the next few days to make it competitive again with Nigeria.

Should the new price for North Sea oil fall much below Nigeria's, the likelihood is for renewed pressure on the OPEC structure. "I am not ruling out a price war if non-OPEC producers want it," Yamani said.

The uncertainty over the British move reflects the tentative nature of OPEC's decisions today. While the organization salvaged a semblance of solidarity, analysts believe that OPEC has been substantially weakened by the disputes.

Ministers could not say whether all 13 delegations had signed the accord, and opinions varied on whether each government would have to "ratify" it. While these seemed to be procedural matters, the fact that they were not resolved shows the haste of the final deliberations, oil industry sources said.