Two longtime residents and artists as well as tenants in 18 other units will be able to stay in rent-controlled apartments thanks to two non-profits buying six buildings from a landlord who decided to back away from evicting tenants and instead sell the buildings to the city.

The purchase, part of the city’s small sites program, will mean that the units remain affordable housing. The San Francisco Community Land Trust and the Mission Economic Development Agency will purchase the buildings.

The deal, “really has the potential to be a win-win situation,” Richard Hurlburt of the SF Community Trust said in July during negotiations. “They get out from under the bad press of evicting tenants and tenants get to stay.”

René Yañez, a Mission artist who started the annual Day of the Dead art installation and was one of the founders of the Galería de La Raza and the Mission Cultural Center, is one of the tenants affected by the purchase. As a result of the deal, Yañez and his partner, Cynthia Wallis, will be able to stay in their apartment. Yolanda Lopez, his former wife who is a well-known Mission artist, also lives in one of the Mission units being purchased.

At a recent art opening, Yañez said he had only recently heard that the deal had gone through. “It has been a lot of work by a lot of people,” he said adding that he was happy to be able to stay put.

Lopez said the nearly three years of uncertainty had made her “numb” to the possibility of it all being over.

All of the parties involved were reluctant to talk about the details of the purchase as they were still completing the deal, but the purchase agreement has now been signed, according to several sources.

During the past two years, the landlord, Sergio Iantorno has served eviction notices to 60 tenants in his buildings.The anti-eviction mapping project branded him as one of 12 landlords it calls the “dirty dozen,” or serial Ellis Act evictors. The latter is a state law that allows landlords to take their property off the rental market.

For more than two years, the Tenderloin Housing Clinic has been working to keep Yañez and his wife in their apartments on San Jose Avenue. “This effort convinced the property owner to sit and negotiate the sale of the properties,” said Dairo Romero of the Mission Economic Development Agency who helped broker the deal. “Saving these properties means that 25 families will be spared from eviction.”

Iantorno, who is in his 70s, declined to comment on the deal.

Three of the properties that purchased by the non-profits are in the Mission District – two of them on Guerrero Street and San Jose Avenue – and the other three are in SoMa, NOPA and Duboce Triangle.

The nonprofits did not disclose the price, but the city’s small sites program pays market rate. The benefit is that the program immediately saves housing and some housing officials believe the city should buy even more existing housing, arguing that it offers immediate housing for lower-income residents.

Although the funds allocated for the small sites program have all been used, it is likely that the small sites program will be part of the discussion on how the city will divvy up the money if voters approve November’s $310 million bond measure.

The deals are also attractive to landlords who can get market rate prices without having to face the acrimony that comes with protesters hounding them. Protesters did exactly that when they rallied against Iantorno at his brothers’ Italian shoe store in Hayes Valley.

The purchase means the units will be turned into tenant cooperatives. The buildings will be leased from the two non-profits.

MEDA will enter into a loan to pay the rest of the mortgage off with the rents and its own pot of money.

Yañez, Lopez, and their son, artist RioYañez, were served with the Ellis Act eviction in 2013.

Throughout the ordeal, the artists made art out of their situation. Yañez and his son’s curation of the annual Day of the Dead Celebration reflected some of the experiences of displacement. For her part, Lopez made art from the documents of eviction and with the collaboration of Adriana Camarena, a lawyer and writer, turned them into a procedural art piece for a March 2014 show. Then, in May of last year Lopez and Rio Yañez transformed a garage sale into an artistic statement. Rio Yañez moved to Oakland, but his parents stayed put and as time wore on, the stress increased.

Lopez said the last year has been especially difficult because for the first three months of the year she had to dodge process servers intent on giving her an eviction notice. They would come at all hours, she said. At one point she looked out her window and a friend could tell it was a process server because of the folders lined up on the dashboard of his car.That cat and mouse game, she said, stopped once negotiations began with MEDA and the owners.

The Yañez case struck a nerve among the Mission community not only because of the many contributions Lopez and Yañez have made to the art scene, but also because both Yañez and his partner have terminal cancer. In a sense, their plight and the publicity it garnered helped protect tenants in the other buildings.

Iantorno told Supervisor Scott Wiener in a letter last year that he felt unjustly vilified after the supervisor tried to talk him out of evicting Yañez.

“We are willing to do our part to house the elderly and the poor, but we firmly believe the city is attempting to shift to us, and to similar property owners, the entire burden of housing poor and disabled people in San Francisco,” he wrote.

In the end this promises to be the rare win-win situation between landlord and tenant.