The legislation, proposed by the socialist PSOE party on Wednesday, will allow judges to suspend the demolition of homes found to be built illegally by developers until owners have been compensated, Teleprensa reported.
Previously, judges lacked the authority to enforce payment to owners. Due to the illegal status of the homes, they could then be bulldozed at any time.
For Maura Hillen, president of pressure group AUAN, the senate vote to amend the penal code comes as a hard-fought victory.
"Obviously we are very pleased," she told The Local. "The text was approved unanimously, it is not quite as clear as the one we proposed, nevertheless, it's a step forward for homeowners."
More than 250,000 homes were built illegally during the construction boom between 2001 and 2008 in Andalusia alone, according to The New York Times, and then often bought by unsuspecting foreigners, looking for vacation and retirement homes.
Housing developers have faced jail time for the 'illegal villa' scandal when they did not secure the proper building permits, but the illegal status of the homes meant they could be demolished at any time.
"Now, many people can go to sleep in peace with the assurance that their house will not be demolished if they are compensated before, and this will also improve the image of our country and our province internationally," said PSOE member, José Luis Sánchez Teruel.
Homeowners were pessimistic about their chances going into the senate hearing, as the ruling Popular Party's position, up until Tuesday, had been against the amendment.
"We were expecting to go down in a blaze of glory," said Hillen. "But I think there must has been a perfect storm in our favour."
The homeowners group had the support of the opposition PSOE, who not only proposed the amendment to the penal code, but also campaigned in the homeowners' favour in the run up to the vote, including appearing on national television.
According to Hillen, the PP also faced pressure from mayors in Almeria as well as other Andalusian towns, some of which have had dozens of expat homes demolished.
Hillen knows only too well what the homeowners are going through, having discovered in the early 2000s that her Almerian home had been constructed without a building license. But, as she explained to The Local, proceedings are somewhat of a lottery; hers were never followed up.
After her close shave with house demolition, Hillen formed an association to help other homeowners in a similar predicament.
"There are over 100 homes in Almeria currently facing demolition," she explained, "as well as 17 in a neighbouring town and in yet another town, nearly every house."
One British couple had their retirement home demolished last year after officials determined it had been illegally built on rural land.
To date, five British couples have lost their homes and life savings due to the legal vacuum, with more cases in the pipeline.
While the new legislation comes as a breakthrough, there is still work to be done to make sure all owners receive compensation.
The new amendment only covers buildings that were constructed without a building license while all other buildings are not covered by the law.
But for now, homeowners are celebrating.
The PSOE said they had rarely seen such unanimity, a sure sign of the Spanish government acknowledging there is a problem, which will likely lead to further action.
For Hillen and the hundreds of expats like her, the process is a long one but one they are willing to pursue to the end.
"There's no magic wand," she said, "but this is a little twinkle."