Out on the western fringe of Ocean City, inside a storage tank at an abandoned service station, rest 24,000 gallons of what is possibly the most expensive gasoline in Maryland.

This modest reserve of unleaded gasoline, less than 3 percent of the amount sold at the resort town during an average summer month, was bought the other day by Mayor Harry Kelley at a cost of $1.38 per gallon -- nearly 50 cents above the going retail price at local stations.

Kelley, who runs Ocean City with the style of a circus showman, says this extra tankful of gas has a psychological value for beyond its cost in real dollars. He calls it "my insurance policy" and says it is "proof positive" that he meant it last month when he promised gas-conscious tourists they could get to Ocean City and back without running out of fuel.

But to some Ocean City Council members, "Kellev's Gas," as they call it, is unnecessary, unclean and unwanted. They say the resort has sufficient gas at a lower price and that the expensive fuel may end up in the city's car fleet, which would cost taxpayers $12,000.

And to officials at the Department of Energy's regional office in Philadelphia, the Ocean City gasoline deal appeared curious enough to warrant an investigation of the firm that sold the fuel -- the Supreme Petroleum Co. of New Jersey.

As that investigation continues, the gasoline at the abandoned station is a symbol of one resort town's frantic response to the 1979 energy crisis.

The Ocean City saga began in May, when Kelley realized the resort season might be disastrous if summer visitors from Baltimore and Washington feared they could not get to the ocean and back without running out of gasoline. Kelley, a confident salesmen, announced he had a "secret plan" to get all the gasoline his town would need.

Kelley would not say what his secret plan was primarily, he now admits, because he was not sure he could accomplish it. He idea was to look for gasoline on what is called the "spot market" -- an unofficial, worldwide network of gasoline traders who buy and sell imported fuel om a spot basis at unregulated prices.

"Some people say it's a black market, but it ain't even a gray one," Kelley said yesterday. "It just takes ingenuity to find it."

Kelley's ingenuity, he said, took him down "99 dark alleys. I tried any of them and all of them. Nobody knows what I went through. I never had one this tough. I just kept moving, and one contact led to another. I just kept talking to all my old friends and politicins, looking for that gas. Finally, I hit, in that 100th alley."

Kelly's 100th alley was the Supreme Petroleum Co. of New Jersey, an oil trading company with offices near Dulles Airport. On June 23, with the council's blessing, Kelley bought 48,000 gallons of gasoline from Supreme for $1.42 per gallon.

Kelley sold the gasoline to several local stations for 92.4 cents per gallon with the city in effect subsidizing 50 cents per gallon for the visiting tourists.

The mayor and his "ocean City supporters declared the plan a success, noting that tourist business, although down somewhat from past years, was appreciably betterr than at other ocean resorts.

But some local service station owners questioned the need for the plan. "I think all it did was get enough gas out there to allow the kids to fill up and race up and down the highway," said Ed Ellis, co-owner of three Exxon stations in town, who rejected the "kelley Gas" because he was "uncertain about the source."

Last week, when the first 48,000 gallons ran out; Kelley went before the council asking to buy another 28,000 gallons on the spot market. The council, in a less receptive mood, rejected the plan last Friday. "It just seemed to us that it was highly questionable whether we needed it," said councilman Guy Ayres.

Kelley called the council's rejection "the worst decision I've seen in 26 years of government."

Businessmen in the audience applauded Kelley and began donating money to help him buy the gasoline. Dennis Devlin, owner of a Boardwalk gift shop, gave Kelley $1,000, one councilman said. Another man, who said he was "the smallest businessman in Ocean City," gave $100.

Monday night, at the next council meeting, town officials had changed their minds. They gave Kelley permission to buy the z$28,00 gallons, provided they could decide when and how to use the gasoline.

"It was a difficult decision," said Ayres, nothing that the council knew when it voted that Kelley would again be buying from a company under investigation. "I felt uneasy about it but I would have felt more uneasy if we were left without gas."