A sharp increase in gasoline costs pushed consumer prices up 0.2 percent in May, the first increase since January, to end the steepest slide in prices in 37 years.

Gasoline prices, which had fallen 26.5 percent during February, March and April, rose 2.5 percent last month and were largely responsible for the overall increase in the consumer price index, the Labor Department reported yesterday. However, other energy costs, such as fuel oil, electricity and natural gas, continued to fall, Labor said.

Consumer prices still have risen only 1.6 percent during the last 12 months and have fallen at an annual rate of 1.4 percent so far this year. Prices rose 3.8 percent during all of 1985.

Economists said yesterday that direct effects of the oil-price drop have ended, but that indirect effects resulting in lower heating, electrical and fuel costs for businesses will help keep retail prices low for many months.

Economists earlier this year had said that the economy would get a big boost from lower energy prices because consumers and businesses would increase purchases as their inflation-adjusted incomes increased. However, most of the effects so far have been negative, as oil companies in Texas, Louisiana and Oklahoma have shut down operations and laid off workers because business became unprofitable.

Earlier this week, the government reported that gross national product -- the nation's output of goods and services -- increased at a much slower rate in the first quarter than earlier predicted. Economists said they expect output to be even worse in the current quarter, but that growth should pick up later on.

The modest increase in inflation last month also gives the Federal Reserve Board an opportunity to push interest rates down further to boost economic growth, economists said. Fed members reportedly want to see how the economy progresses following the previous round of interest-rate reductions before pushing rates down further.

Reagan administration officials said this week that they would like to see rates go lower.

The White House yesterday was upbeat about the inflation report. Spokesman Larry Speakes said, "With inflation still under control and consumer spending up, we expect continued brisk activity in the consumer sector."

Private economists also said they expect consumer spending to improve despite the increase in prices. They said that it takes several months after the initial price declines for consumers to realize how well off they are before they begin spending again.

Businesses will start spending as they realize their costs are lower, economists said.

However, the latest Commerce Department survey of business spending plans shows that companies -- particularly in the energy industry -- expect to spend 1.3 percent less this year than last year.

"We will begin to see positive effects of lower prices later this year," said Martin Mauro, senior economist for Merrill Lynch Economics. But he added, "We haven't seen the end of negative effects either. The biggest drops have passed us by, but more declines are coming."

Allen Sinai, chief economist for Shearson Lehman Bros. said: "The direct beneficial effects of lower oil and energy prices have probably ended." But he said that the total effects of lower crude oil prices have not yet worked their way through the entire economy.

"Those effects are in . . . the business-production cost side as lower oil and energy prices impact on electricity costs, materials, supplies, plastics, chemicals," Sinai said.

"If costs of production are lower and product markets are weak, business cannot raise prices. The typical American business is spending less on gasoline to fill up its cars and trucks. It's spending less to heat and run and air condition an office."

Economists said that, as long as price increases stay moderate, it should encourage business and consumer spending.

"Gasoline prices will not rise so much as they did in May," Sinai said. "The outlook for retail price inflation looks very bright."

Despite the increase last month, gasoline prices were still at their mid-1979 level and were 33.3 percent below their peak of March 1981, Labor said.

New car prices rose 0.8 percent in May as both domestic and imported car prices rose. Used-car prices, however, fell 1.9 percent and car-financing charges also declined by 2.6 percent.

The index for fuel and other utilities declined for the fourth consecutive month. Prices for fuel oil for homes fell 5.1 percent in May and have dropped 26 percent so far this year. They are 33.8 percent below their peak in April 1981.

Electricity prices fell 0.9 percent and natural gas costs dropped 0.1 percent in May, both for the third consecutive month.

Food and beverage prices rose 0.4 percent and were 2.8 percent higher than they were 12 months ago, Labor said. Medical costs continued to increase, rising 0.6 percent, the same as in April. Apparel costs fell 0.2 percent.

The consumer price index in May stood at 326.3, meaning that goods costing $10 in 1967 cost $32.63 last month. Another CPI measure, used in collective bargaining contracts and for some federal benefits, such as Social Security, also rose 0.2 percent to 321.4.

In a separate report, the Labor Department said the average weekly earnings of Americans declined 0.1 percent last month after discounting for inflation. A 0.3 percent rise in hourly earnings was offset by a 0.3 percent drop in the average number of hours worked and the 0.2 percent rise in inflation.