The flats in Lorne Street, owned by The Miss Agnes Hunter Trust, are being sold to Places for People Scotland.
The trust said the costs of the 92 flats were diverting funds from the causes it was set up to support.
Residents, who feared for 18 months they might lose their homes, said it was "absolutely fantastic news".
Places for People Scotland confirmed the sale of the property portfolio would not affect the lease agreement and rights of the tenants.
The Miss Agnes Hunter Trust is a grant-making charitable trust set up by her will in 1954 to provide financial help to charitable organisations which support health and social welfare in Scotland.
Walter Thomson, chairman of the Miss Agnes Hunter Trust, said: "The trustees have considered the offer carefully and are confident that Places for People Scotland and its associated organisation Castle Rock Edinvar have the expertise and resources to take management of the property portfolio forward and that the sale is in the best interests of the tenants.
"We have written to the tenants informing them of the sale and advising that The Miss Agnes Hunter Trust will remain their landlord until the settlement date of 28 November 2016 after which tenancies will transfer to Places for People Scotland.
"The sale will enable the Trustees to carry out the specified wishes of Miss Hunter by maintaining the financial grants to registered charities which support people suffering from arthritis and cancer, physical disability and mental health problems or learning disabilities, or which provide youth education and training for disadvantaged people.
"Currently grants amount to around Â£350,000 each year."
Melanie Weigang, 48, secretary of Lorne Street Association, told the BBC Scotland news website: "This is absolutely fantastic news and a huge relief.
"This has been dragging on forever and to find out before Christmas that we are not going to be evicted is just brilliant.
"There are a lot of elderly people who have been living in Lorne Street for decades and families use the local school so they did want to move from their homes and the area."
Alister Steele, managing director of Castle Rock Edinvar/Places for People Scotland, has also written to the tenants introducing their new landlord.
He said: "We are pleased to be able to finally announce the purchase of the 92 properties from Agnes Hunter Trust and end a period of uncertainty for the residents.
"We have a proud track record in investing in Edinburgh's housing stock and in managing the purchase of tenanted housing.
"We will now begin a dialogue with the residents to give reassurance on our commitment to the future of the properties and to discuss our services and investment plans.
"We would like to take this opportunity to thank the Scottish government and City of Edinburgh for their help on this matter."
Deidre Brock MP said: "I'm thrilled to bits to hear this news.
"What a fantastic day for the tenants of Lorne Street who have been worried about eviction since June last year."
Cammy Day, of City of Edinburgh Council, said: "I am really pleased that we have reached a positive solution for the residents of Lorne Street.
"The council and our partners have been working closely with tenants since they first approached us over a year ago with concerns that they might be made homeless."
Tenants who were facing eviction from their homes in Leith are being allowed to stay after a housing association was found to buy the properties.