Evicted 87-year-old Maricarmen Abascal can return to the apartment she has lived in for decades, her lawyer has said.
Ms Abascal will pay rent similar to the one she had under a new eight-year contract agreed with the building's owner, her lawyer Beatriz Duro told reporters on Monday.
The wheelchair user, who was taken to hospital after being evicted, will sign the deal once she feels better, Ms Duro said.
Her landlord has not commented.
Last week, the octogenarian was given just 30 minutes to leave with only essential belongings before she was forcibly removed from the building on a stretcher, accompanied by social services officials.
She was driven away in an ambulance as supporters chanted "Murderers!" and "Maricarmen, you're not alone!"
Her eviction sparked protests over Spain's housing crisis, with 30,000 demonstrators marching through the city on Saturday, some chanting, shaking keys, setting off flares and carrying banners with slogans including: "Speculators go home" and: "Housing is for living".
By Monday, hundreds of tents filled the central Puerta del Sol square, 15 years after the same area was occupied
for a month by activists demonstrating against austerity measures adopted during the global financial crisis.
While in hospital, Ms Abascal told protesters in a video message distributed by the Tenants' Union that she could not join the demonstration and urged protesters to keep fighting.
"Be brave, fight, defend what is yours and, please, take care of yourselves; keep camping there for as long as your
bodies can hold out and as long as you wish to. Let's hope all this comes to a successful conclusion tomorrow."
Spain's Prime Minister Pedro Sanchez said his cabinet, which meets on Tuesday, would approve some housing relief measures but did not provide details.
He said protecting vulnerable tenants "is not a matter of ideology but of humanity".
Mr Sanchez's left-wing coalition government and conservative-led Madrid regional government are at odds over how to deal with the country's housing shortage.
The case highlights heightened pressure on long-term tenants in major Spanish cities, where soaring rents, gentrification and a lack of affordable housing have sparked social and political tensions.
More from Sky News:
'Foreign actor' involved - Fairford latest
Ex-champion jailed for child sex abuse
Spain has a shortage of 750,000 homes, according to its central bank, which has said that figure could rise to over one
million by 2028 and only about 120,000 are built each year.
The apartment, in the capital's affluent Retiro neighbourhood, had been acquired by an investment fund that sought a steep increase in her rent.
Courts blocked three previous attempts to evict her.
Ms Abascal's father first rented the property in 1956, and she continued as the tenant after her parents died, during which time there was a rent cap, Spanish media reported.
(c) Sky News 2026: Woman, 87, whose eviction sparked protests can return home, lawyer says
Police investigating after newborn baby's body found along shoreline in Bangor
Thousands of wildlife crimes going unpunished, campaigners warn
Rugby World Cup winner Lawrence Dallaglio forced to sell medal following bankruptcy
Investigation into alleged gang rape at Cornell University reopened by prosecutors
Russia's spy agency opens criminal case against Lib Dem councillor