After 18 months of negotiations, the developer of St. Charles, Md., has worked out a complex refinancing scheme with the federal government and three private lenders that is designed to spare the southern Maryland "new town" an uncertain financial future and permit development of 3,600 new building sites over the next eight years.

The developer, St. Charles Associates, has arranged a $23.4 million refinancing package with Perpetual American Federal Savings and Loan and the American Security Bank, both based in Washington, and the Chemical Bank, based in New York.

The firm also plans to repay the Department of Housing and Urban Development $22.5 million of the original financing for development of the town, which HUD guaranteed under a federal new communities program. HUD officials said the the program, begun in 1968 to promote development of planned new communities, will be closed down this year because most of the "new towns" have failed financially.

Like all but one of the other 12 communities that received federal financing guarantees under the program, St. Charles ran into financial trouble early, missing its first interest payment in 1974 on a total debt of $38 million, four years after HUD guaranteed the project's first bond issue.

Eight years later, St. Charles faced a total outstanding debt of at least $64 million, including interest payable through the maturity of the bonds and interest paid by HUD on behalf of the developer over the last six years.

St. Charles Associates President Charles Stuart blamed high interest rates and the resulting housing-sales slump for the project's poor financial performance. But he thinks the refinancing arrangement will give the town a new chance to turn a profit, perhaps as early as this year.

"We have better potentials than at any previous time because our carrying cost is less," he said. Part of the refinancing is equity, he explained, which reduces the interest costs on the town's financing.

Under the refinancing scheme, HUD will take a substantial loss, said Joseph Sens, acting comptroller of the New Community Development Corp. He said the department agreed to take a loss because it believes the community is viable and because foreclosure and liquidation probably would not bring in any more cash.

Sens said HUD will be responsible for repayment of about $30.7 million in outstanding principle on the original project bonds, and $19.7 million in interest payments through maturity of the principle balance. HUD has already paid out $8.7 million in interest on behalf of St. Charles Associates. The department provided another $25.2 million in grants for infrastructure development to the town and surrounding Charles County.

St. Charles Associates will pay HUD $8.5 million in cash immediately and $8.5 million in notes over seven years, according to Edwin L. Kelly, St. Charles Associates vice president and treasurer. He said the firms will continue to pay off one of the original project bond issues, which has a principal amount of $5.5 million.

Among the private lenders, Perpetual Federal is making the biggest commitment to the town. Kelly said Perpetual is loaning St. Charles Associates $12 million at 14 percent on a three-year renewable term, for acquisition and development of land for 3,600 housing units in Westlake Village, the second of four villages planned for the site.

St. Charles Associates agreed to a joint venture with Perpetual under which it will share profits from Westlake Village with the lender on a 50-50 basis after paying debt service. In return, Perpetual made the loan on a non-recourse basis, meaning the Westlake village land is the only security for the loan.

Chemical Bank is providing an $8.4 million letter of credit to secure the notes St. Charles Associates are using to pay part of its settlement with HUD, Kelly said. Under terms of the notes, St. Charles will pay HUD up to 60 percent of its net revenues, excluding sales of lots in Westlake villge. HUD could draw on the letter of credit if St. Charles does not pay off the notes within the specified time.

American Security Bank is extending $3 million in various forms of financing to help St. Charles Associates merge and expand two separate cable television systems in the town and surrounding county, Kelly said.

St. Charles Associates raised an additional $3 million by asking its limited partners to prepay their investments and by selling its water and sewer utility, he said.

"We wound up with a little cash to pay our legal fees and our accountants and to go into the new year with minimal payables," said Kelly. "It was a very complex and interesting transaction."

Stuart said the key to refinancing was breaking the development's financial needs into individual components. He said previous efforts to secure refinancing in one lump sum were unsuccessful. Stuart also gives HUD credit for paying interest on the bonds on behalf of the development, a step that allowed the firm to put money into development of more land to prepare for an improved housing market.