The credit rating of General Motors Corp.'s long-term debt was lowered yesterday by Moody's Investors Service Inc., which said that the nation's largest auto maker will have difficulty regaining the huge chunks of U.S. auto market share it has lost in recent years.

GM has $54 billion in long-term debt.

The downgrading -- to Moody's fourth-highest rating, Aa-3 -- could increase the cost of future GM borrowing, said Samuel Gordon, a Moody's senior vice president.

"To the extent that ratings affect interest costs, we expect that these changes will have an effect on GM's costs," Gordon said. GM's debt previously carried Moody's second-best rating, Aa-1.

"The rating actions are based on the probability that GM is not likely to recover its former dominance of market share, and will continue to remain behind its leading competitors in cost performance" in the next several years, Moody's said in its GM ratings report.

GM has the highest production costs of the nation's three largest auto makers, including Ford Motor Co. and Chrysler Corp. All three trail behind Japanese car companies in production costs.

Standard & Poor's Corp., also citing GM's reduced market share, lowered its ratings of GM's bonds last month.

GM's share of the U.S. auto market fell to 37 percent in 1987 from 41.1 percent a year earlier. In 1984, its share of the U.S. auto market was 44.3 percent.

Declining market share has been accompanied by declining prestige and a rising drumbeat of criticism of the once-invincible car company. Indeed, company officials have been so upset by what they call "GM-bashing" that they spent an estimated $20 million in New York last week to put on a three-day display of their technology and future products.

Some 14,000 people, including many auto industry analysts, attended the event, and many said they were impressed. Others complained that the futuristic products indicated little about GM's ability to compete effectively in the next few years.

In its report, Moody's said that GM "remains a formidable competitor" with good products. The ratings service also said that GM remains "financially sound, with a healthy capital structure, good debt protection and solid cash-generating ability."

But the rise of foreign competition, particularly the increasing number of foreign companies building vehicles in the United States, casts doubt over GM's ability to exercise the kind of sales muscle it had in the past, Moody's said.

GM officials said in a statement that despite Moody's decision to lower the company's debt ratings, "we were pleased to see that Moody's properly noted that General Motors remains a formidable competitor, with large market shares at the more profitable ends of the car and light truck segments."

Moody's also lowered the ratings of certain bonds of General Motors Acceptance Corp., GM's financial arm. GMAC bonds dropped from Aa-2 to A-1, or from Moody's third-best to fifth-highest ranking. Moody's let stand the Prime-1 rating of GMAC's commercial paper. Prime-1 is the rating service's top mark for short-term loans.