The homeless mothers who took over a vacant house in Oakland, California, and occupied it for almost two months will be allowed to purchase the property – a major victory in a movement working to keep such homes out of the possession of speculators.

The group Moms 4 Housing entered the house on Magnolia Street on 18 November with the intent to stay. The house had sat vacant for more than two years before it was purchased in July at a foreclosure auction for $501,078 by Wedgewood Properties, a real estate investment company with a history of buying up foreclosed-upon houses cheaply, evicting the tenants, renovating the homes and then putting them back on the market at much higher prices.

Housing advocates say companies such as Wedgewood fueled the housing crisis that now grips the state, which needs anywhere between 1.8m and 3.5m new housing units by 2025. More than 15,500 units remain vacant in Oakland alone, according to the latest US Census Bureau data, while 4,071 people are homeless. House-flipping has led to rapid gentrification, which then in turn led to the widespread displacement of black residents.

In Oakland, 78% of the homeless population reported that their last place of residence before becoming homeless was within county limits. Seventy per cent were black.

Moms 4 Housing chose the Magnolia Street house in part to try to force Wedgewood to negotiate the sale of the home back to the community.

“This is what happens when we organize, when people come together to build the beloved community,” Dominique Walker, one of the mothers who lived in the house with her two children, said in a statement, on the day that America marked Martin Luther King Day. “Today we honor Dr King’s radical legacy by taking Oakland back from banks and corporations.”

With the housing and homelessness crisis worsening each day, the mothers received widespread support for their cause, from local lawmakers to California’s governor, Gavin Newsom, who praised the activists.

Moms 4 Housing had brought the issue to court, but a judge ruled in favor of Wedgewood. Sheriff deputies arrived in the early hours of 15 January to evict them, arresting two of the mothers and two of their supporters.

Wedgewood has maintained that the mothers had committed a criminal act in breaking into the house, and the house legally belonged to the company.

“Wedgewood has always been and continues to be open to thoughtful and purposeful discussions,” spokesman Sam Singer said in a statement.

“After regaining possession of Magnolia Street, we engaged in discussions with governor Gavin Newsom, mayor Libby Schaaf and councilman Larry Reid. These led to progress that everyone should agree is a step in the right direction in helping to address Oakland’s homelessness and housing crisis.”