The problem began when a southern Maryland bank foreclosed on a 118-acre farm in St. Mary's County.

But what seemed at first like a relatively simple transaction turned into a painful precedent for both the banking industry and for would-be borrowers.

Maryland Bank and Trust ended up with the farm after an auction failed to produce someone willing to pay the minimum bid. In the meantime, the farm's former owner had alerted authorities to potential environmental hazards on the property.

The Environmental Protection Agency soon discovered hazardous waste on the site -- possibly the residue of paint cans and chemical drums disposed of there more than 20 years ago. Despite the bank's assertion that it had been unaware of the waste and should not be held responsible for it, EPA sent the bank a bill for approximately $500,000, according to William M. Loker, assistant to the president of the bank.

When the bank declined to pay, the EPA sued and won a judgment in U.S. District Court that the bank was liable for the cleanup. Rather than fight on, the Maryland Bank and Trust settled, agreeing to pay more than $400,000.

In retrospect, Loker said, the bank should have appealed instead of allowing the 1986 lower court ruling to stand. "We apparently made some law, and, in the opinion of many, bad law," he said.

As a result of series of judicial rulings that began with the Maryland Bank and Trust case, banks and savings and loans across the country are increasingly getting stuck with the costs of toxic waste cleanups on properties on which they foreclose.

To help pay for the unexpected liabilities, banks are charging would-be borrowers stiff fees for environmental audits or are refusing to make loans to properties that pose a high risk of being declared in need of cleanup. These stiffer lending practices are making it that much tougher for some businesses to get loans at a time when borrowers already face a tightened market for credit.

For some types of businesses, like gasoline stations, dry cleaners or businesses that involve underground tank storage of chemicals, the risks are high enough to shut them off from borrowing altogether, said John Bowers, executive vice president of the Maryland Bankers Association.

The state of Maryland, receiver for Baltimore's defunct Old Court Savings and Loan, found itself paying to clean up a site contaminated by hazardous waste long before the state inherited the S&L. And the Resolution Trust Corp., the federal agency that has taken over hundreds of insolvent S&Ls, says it expects some of the properties it inherited also are contaminated.

Members of Congress say that when they imposed the 1980 Superfund law to finance toxic waste cleanup, they never intended that financial institutions be held responsible for hazardous waste on properties acquired temporarily through foreclosure.

When it drafted the Superfund legislation, Congress exempted security holders -- lenders who end up with title to property used as security on loans -- from Superfund liability, said Rep. John J. LaFalce (D-N.Y.).

"Despite this clear legislative language, courts -- in their search for deep pockets -- have held lenders liable for cleanup costs when they exercise their rights by foreclosing on their security interest," LaFalce said.

EPA Administrator William K. Reilly said his agency also had not intended for the banks "to get stuck with the costs, and we haven't adequately addressed this."

He said that EPA officials are working with the Justice Department to try to resolve the issue.

More recent court decisions have broadened lenders' liability and prompted LaFalce and Sen. Jake Garn (R-Utah) to introduce bills that would provide an exemption from liability for lenders who inherit rather than create contamination.

The rising concerns over liability have created a new market for attorneys and environmental consulting firms that help banks assess their potential Superfund liabilities on loans.

"We are doing about 1,000 audits a year," said Robert P. Ouellette, who heads Versar Inc., an environmental risk management firm.

James P. O'Brien, an attorney with Chapman and Cutler in Chicago, testified at a recent congressional hearing on Superfund liability that lenders he surveyed paid an average of $4,500 for environmental audits.

"Based upon those survey results, we projected that approximately $418 million will be spent on environmental audits for environmentally risky transactions through the 1990s," he said.

But even with an environmental audit, some risk remains, said the Maryland Bankers Association's Bowers: "It's kind of hard to continue lending with the skill that is needed and to avoid all the problems that are lurking out there."