Spain's socialist government has suffered a catastrophic defeat in a regional election, after PM Pedro Sanchez opened the door for an estimated 500,000 undocumented migrants to get legal residency. The Socialists won just 28 seats in the 109-seat regional parliament, down two from four years ago, in Sunday's vote. After resounding defeats for the left in three previous regional elections, the debacle in Andalusia will be particularly painful for Sanchez, whose candidate is his former deputy and ex-finance minister Maria Jesus Montero.The defeat also follows recent losses for the Socialists in the regions of Extremadura, Aragon and Castile and León, increasing pressure on Sanchez before a general election expected in 2027.In April, Sanchez approved plans to give legal status to half a million undocumented migrants, calling his decision an 'act of justice' and a necessity for Spain. He claimed the controversial policy will help 'build the rich, open and diverse Spain that we are and to which we aspire.' But footage from shortly after the policy was announced showed migrants seeking legal status in Spain have been seen fighting each other while queuing. Individuals were waiting for hours at more than 400 locations across the country for appointments after submitting online applications.Migrants were pictured in long queues outside registry offices in regions such as Catalonia, Andalucia and Madrid. In a desperate rush to finalise their paperwork, some migrants were waiting in line for hours or staying overnight to get their documents officially stamped. Dozens of desperate migrants scaled the walls of the Gambian embassy in Madrid in April People queue to receive documentation as Spain's mass migrants regularisation process is set to start, in Hospitalet de Llobregat, near Barcelona, Spain, April 20, 2026 Tensions rose as the crowds have overwhelmed registry offices and those seeking to confirm their legal status grew restless.Sanchez has also been dealing with the fallout of the Iran war, which has seen a huge spike in the price of oil, gas and energy. This has also resulted in huge queues of people in airports, as airlines cancel more and more planes to and from Spain. And while Sanchez has built up his own status on the world stage by opposing US president Donald Trump's war, as well as his push for Spain to spend more on NATO defence, Paco Camas, head of public opinion in Spain for polling firm Ipsos, told the FT that international issues had little to no effect on the outcome of the Andalusia race. Andalusia - a sun-soaked tourist magnet famed for its beach resorts and historic cities such as Seville and Granada - was governed by the Socialists for nearly 40 years until the conservative People's Party (PP) took power in 2019.One of the biggest surprises of the night was the strong showing of the left-wing regional party Adelante Andalucia, which went from two seats to eight.The PP this time won 53 seats, but fell short of an outright majority and is expected to rely on the support of the hard-right anti-immigration party Vox to govern.Vox came third with 15 seats, one more than previously, strengthening its leverage in negotiations with Andalusian president Juan Manuel Moreno and becoming something of a kingmaker in the region. Vox has already struck coalition pacts with the PP in two other regions, having made immigration a central focus of its campaigns. Many of the migrants had spent the entire night queuing outside the building just to obtain the required documentation back in April Video footage captured a chaotic brawl among a group of male migrants while hundreds looked onIt has pledged to introduce a 'national priority' to give Spaniards preference in accessing public housing, services and welfare benefits. Manuel Gavira, Vox’s leader in Andalusia, said: 'Many voters have made clear what they want — and what they want is the "national priority" policy.'The Andalusia result marked a partial disappointment for Moreno, whose PP party lost five seats compared with the previous regional election in 2022. 'Andalusians have given us a clear mandate ... to continue the transformation of Andalusia,' Moreno said after the result. He had relied on Vox support to govern the region since 2019.The PP has formed coalition governments in Aragon and Extremadura and is in talks to do so in Castile and Leon.,The PP has not ruled out cooperation with Vox at the national level if the general election produces no clear parliamentary majority.