Spanish lawmakers on Thursday backed a law granting citizenship to tens of thousands of Western Saharans who were born when Spain ran the disputed territory now largely controlled by Morocco.

The vote comes at a particularly sensitive time for Madrid's historically delicate relations with Rabat due to the migration crisis in Spain's north African territory of Ceuta.

Parliament passed the initiative by 168 votes to 31, but it must obtain approval in the Senate before becoming law.

The text grants Spanish nationality to Sahrawis born before September 29, 1977 and to their children through a certificate of naturalisation, considering that date the effective end of decolonisation.

Although the exact number of beneficiaries is unknown, around 80,000 Sahrawis are believed to be eligible, with some estimates reaching almost 200,000 including the descendants.