Fifty-nine units of affordable housing have been preserved in Dorchester and Mattapan through a $5.6 million sale of several properties, tying up a saga of what tenants asserted was a long-term problem of property mismanagement and negligence on the part of their landlord.

A coalition of law firms, city agencies, and advocacy groups on Thursday concluded legal negotiations on a multi million-dollar sale for properties on Orlando Street in Mattapan and Waldeck Street in Dorchester, according to a release from the law firm Goulston & Storrs. The Codman Square Neighborhood Development Corporation (CSNDC) offer, though not the highest cash offer on the table, was accepted by a trustee over protests from landlord Uwagboe O. Oru-Lawrence.

A federal bankruptcy judge ruled that the non-profit developer CSNDC can purchase the properties located at 91-101 Waldeck St. and 25-35 Orlando St. from the bankrupt landlord.

Included in the agreement was the waiver of more than $3.5 million in tenant claims.

At demonstrations outside the properties since the summer, tenants described squalid living conditions. They complained of roaming mice and cockroaches, dripping water and resulting mold, shut-off heat and electricity. The city’s Inspectional Services Department cited the properties on Orlando Street for 10 violations in June, with ISD Commissioner William Christopher describing jammed doors, exposed wiring, and open gasoline canisters visible during the inspection.

Monique Hinton, a five-year resident of the Orlando Street, said in July: “I am tired of it. Just because I have Section 8 doesn’t mean I don’t have a right to live comfortably. It’s not fair. It’s not right.”

Though Lawrence filed for Chapter 11 bankruptcy in 2013, he operated the properties as a debtor-in-possession until July 2016, according to Goulston & Storrs. The fate of the buildings has been in the hands of trustee, Joseph Butler, who was appointed to administer the bankruptcy proceedings.

Tenants, many reliant upon the buildings’ affordable designations and eligible for Section 8 vouchers, called for a responsible non-profit to purchase the properties at a price point that would not force them from their homes. Their agreement to waive their millions in legal claims was contingent upon the properties being purchased a non-profit like CSNDC and maintained as affordable housing.

"Ensuring that Boston remains an affordable place to live is critical to the future of our city," Mayor Martin Walsh said in a prepared statement. "I want to commend the entire team that worked on the acquisition of these properties for their commitment to the well-being of the tenants who live on Orlando and Waldeck streets, and the tenants for their engagement in this process. Boston is a City that works together to protect its vulnerable residents, and I am pleased we were able to assist. "

After discussions stretching since August for the purchase of the Orlando and Waldeck street properties, CSNDC’s sale closed on Oct. 27.

Butler concluded that the $5.6 million, in combination with the $3.5 million in waived claims, was the highest and best offer. The approving judge held that the tenants’ wishes ”should be taken into consideration in determining the outcome of the matter,” according to Goulston & Storrs.

Housing justice group City Life/Vida Urbana said in the joint release that tenants deserve much of the credit for the success of the final agreement.

“This victory helps refine an important anti-displacement strategy which we call ‘the sword, the shield and the offer’,” said Steve Meacham, organizing coordinator at City Life/Vida Urbana. “The ‘sword’ was the protests and coalition building. The ‘offer’ came from CSNDC. The ‘shield’ was the energetic legal defense provided by GBLS and the incredible pro bono hours donated by the three law firms. We hope to use this model in many other locations where we have organized tenant associations.”

The coalition of supporters working pro bono on the proceedings included the Boston Public Health Commission, City Life/Vida Urbana, the City of Boston, CSNDC, Goulston & Storrs, Greater Boston Legal Services, Jones Day, and Pillsbury Winthrop Shaw Pittman. City Councillor Andrea Campbell also wrote in support of CIty Life/Vida Urbana’s efforts to secure the housing.

These properties, now under non-profit control, dovetail with the city’s plan to increase designated affordable housing units throughout Boston. Through the new Acquisition Opportunity Fund, the City of Boston committed and provided a loan to assist in both the acquisition of the properties and to make the initial repairs and improvements needed to address critical health and safety issues, according to the release.