As San Francisco rapidly loses its desperately needed residential care facilities for the elderly, homeless and mentally ill, the city has come up with a plan — and the money — to save two from closing.

Officials plan to purchase two board-and-care facilities: Grove Street House with nine beds and South Van Ness Manor with 29 beds. The purchases are the first of their kind in recent history, and part of the city’s overall strategy to maintain the homes amid a dearth of long-term options for the city’s most vulnerable.

While the city’s purchases will save a total of 38 beds, they are only one small step toward stemming the tide of closures around the city.

San Francisco has lost more than a quarter of its board-and-care beds since 2012, according to city data. Many operators have blamed their woes on the city’s high cost of doing business, trouble with hiring and retaining staff, and exhaustion from taking care of a demanding population for often little pay in return.

Those factors also increase temptations to sell the homes in San Francisco’s hot real estate market.

Board-and-care facilities are an integral part of the city’s system of care. They are home-like environments that provide care for formerly homeless, elderly and mentally ill people. Residents are some of the city’s most vulnerable, and many would likely wind up homeless if not for the around-the-clock care.

“As we work to improve our entire behavioral health system, we need to make sure our existing resources can continue providing the services that people depend on,” Mayor London Breed said in a statement.

Amid a raft of closures last year, Breed and three supervisors announced a three-part plan to save the facilities: increase subsidies from $22 a night to $35 a night per person for board-and-care operators; make it tougher to convert the facilities into single-family homes; and encourage the city to purchase homes on the verge of closure.

Still, despite the new policies, The Chronicle first reported in October that South Van Ness Manor planned to shut its doors after 38 years of business. In a letter to the state, operator Andres Parangan Jr., said South Van Ness Manor had been struggling financially for years.

“The cost of operating a facility like this in San Francisco has not been adequately compensated,” Parangan wrote in the letter. “Our monthly rent income was not sufficient enough to cover the cost of living in San Francisco or the ongoing necessary repairs.”

As soon as it learned of the closure, the mayor’s office said, officials immediately started exploring how it could purchase the facility. Officials are now negotiating with the owner, but it’s still unclear how much it will cost to buy it.

Meanwhile, the city will pay $3.94 million to buy and fix up Grove Street House. The board-and-care home north of the Golden Gate Park panhandle is a 60-day residential mental health treatment facility. It will continue to be run by nonprofit PRC Baker Places. The funding comes from the Mayor's Office of Housing and Community Development.

The house will need about $675,000 in repairs, including seismic strengthening and upgrades to the electrical, plumbing and ventilation systems.

While these two board-and-care homes are now saved, many other facilities are still vulnerable.

A recent tour of Parkview Inn #1 on Buena Vista Park revealed more than a dozen empty beds in a sprawling, three-story mansion in the Haight-Ashbury. The home announced plans to close last year after caring for people who were formerly homeless and struggle with mental illness and substance abuse. The majority of the residents were moved to other facilities, while about five remained last month waiting for placements, according to the owner, Dellie Punla.

“They are hard clients,” she said last month. “How can you kick them out?”

The closure of the Parkview and other homes comes as more than 5,000 people — many mentally ill and drug addicted — sleep on the streets every night.

According to Shianne Kurkina, the listing agent for the home, Punla is asking for $7 million to $7.5 million for the home. Even Kurkina agrees that price is far too high to be realistic, and she is trying to convince the owner to go lower.

Anyone who buys a board-and-care home has to obtain a special permit to convert it into a single-family home, after an October rule change sponsored by Supervisor Rafael Mandelman. That change, Kurkina said, dramatically dropped interest from buyers for the home.

When asked by The Chronicle if the family would be willing to go lower, Lee Balingit, Punla’s sister, said in a text message: “Maybe.”

City officials plan to do its own property appraisal soon, Kurkina said.

But until everyone can agree on a price, the critically needed beds will remain vacant.

“I personally would love to sell it and keep it” as a board-and-care home, Kurkina said. “But no buyers in their right mind would buy this facility and keep it open, because it is a negative cash flow.”

“It just doesn’t make sense for anyone to buy a business that is tanking,” she added.

Trisha Thadani is a San Francisco Chronicle staff writer. Email: tthadani@sfchronicle.com Twitter: @TrishaThadani