General Motors Corp. gambled millions of dollars that it could fill a gap in a fuel-conscious auto market with U.S.-built diesel car engines.

GM lost.

The company announced Tuesday that it would stop U.S. production of diesel-powered cars by next spring. The announcement took some industry officials by surprise. "I was astounded. It's not like GM to admit defeat," one ranking officer of Ford Motor Co. said yesterday.

But more than that, industry officials and analysts said, GM's decision points out the high-stakes dangers of rushing new products to market to meet changing consumer demand.

GM, for example, started rolling out its diesel-powered cars in the 1978-model year, when consumers were worried about having enough gasoline at a reasonable price.

GM's strength was, and remains, big cars. But buyers were running scared in the late 1970s because big cars had big appetites for gasoline.

Diesel fuel was cheaper then, and diesel engines were far more fuel-efficient than their gas-powered cousins. GM's initial response was to convert many of its big V-8 gasoline engines to diesel units.

The conversion did not work well. There were many consumer complaints about breakdowns and poor performance. As a result, GM last October set up a nationwide program to correct problems or otherwise provide some form of compensation for its disgruntled diesel owners.

But in 1981, GM started producing 4.3 liter, V-6 diesel engines. Most automotive critics agree that these models work well. But they hit the market too late.

Diesel fuel that sold for 97 cents a gallon in the Washington area in September 1979 sells for $1.35 a gallon today, according to figures from the Potomac Division of the American Automobile Association.

By comparison, gasoline sold for $1.01 a gallon in the Washington area in September 1979, and the price today is $1.31. Both the prices for diesel and gasoline represent the average, combined costs of self-serve and full-serve fuels, AAA officials said.

"But this thing goes beyond the fuel prices," said Warren P. Browne, an analyst with Ward's Automotive Research in Detroit. "Gasoline engines have improved so much that even a new, mid-size car today can get about 24 miles per gallon. That takes away a lot of incentive for buying diesels," he said.

GM, for example, sold 350,000 diesels in 1981, compared with a total of 26,200 in the first 10 months of 1984.

All auto makers in the U.S. market sold 99,700 diesel-powered cars in the first eight months of this year, compared with 136,900 during the same period in 1983, according to Ward's Engine Update, a division of Ward's Automotive Research.

GM was more vulnerable to losses in the diesel-car market because it spent its own money (the company won't say how much) to develop and produce most of those engines. Ford had a better idea. "We buy all of our diesel engines from Japan's Mazda Motor Corp. and West Germany's BMW," said L. Ray Windecker, Ford's in-house auto industry analyst.

"Ford was never too enthusiastic about tying up large amounts of capital in diesel engines. The demand was too cyclical. There was a deep dose of 'fadism' in the diesel market," Windecker said.

Chrysler Corp., the third-largest U.S. auto maker after Ford, does not produce diesel-powered passenger cars.

GM's virtual defection from the diesel car market means that Daimler-Benz AG, the West German manufacturer of Mercedes-Benz cars, could become the biggest provider of diesel cars in the United States in the 1986-model year.

Mercedes-Benz currently is the leader in diesel sales in the U.S. market. About 51 percent of the 77,000 Mercedes-Benz cars sold in this country this year were diesel-equipped. But that compares with nearly 77 percent in 1983.

"The difference is not because our diesel sales have gone down drastically. It's that we changed our model mix," said Frederick A. Chapman, spokesman for Mercedes-Benz of North America.

For example, popular models, such as the new Mercedes-Benz 190 series and the Mercedes-Benz 380 SE, are being offered in the United States in diesel and gasoline versions, Chapman said.

"It's a response to the market. But we have a good, loyal group of diesel owners, and we're going to continue to offer those cars in our lineup," Chapman said.