Real Betis were condemned to the final Primera Liga relegation spot when they drew 1-1 at home to Real Valladolid in a nail-bighting final round of matches on Sunday.
Betis and four other teams were in danger of joining relegated Recreativo Huelva and Numancia but it was the Seville-based side who failed at the last hurdle after seven seasons in the top flight.
Superb comeback wins for Osasuna and Sporting Gijon and a battling draw for Getafe kept them up and Valladolid's point also ensured their safety.
Passions were running high at the Ruiz de Lopera in Seville after the final whistle and police had to intervene to prevent angry fans getting into the VIP area and clashed with supporters outside the stadium.
Marcos Aguirre had put Valladolid in front in first-half stoppage time before striker Ricardo de Oliveira equalised four minutes after the break.
Edu hit the Valladolid crossbar with around 20 minutes left and Sergio Asenjo produced a fine save to deny Oliveira in the dying seconds but the visitors held out.
Osasuna, in the relegation places at the start of play, inflicted a fifth straight defeat on Real Madrid when they came back from a goal down to win 2-1 in Pamplona.
Juanfran scored the winner with a stunning volley from the edge of the area after Jaroslav Plasil's tame shot slipped through the hands of Iker Casillas to cancel out Gonzalo Higuain's opener.
Sporting Gijon fell behind to Recreativo in the 23rd minute but came storming back with goals from David Barral and Luis Moran, while in Santander, Racing went ahead through a Toni Moral strike before Getafe's Esteban Granero equalised.
Getafe finished level on 42 points with Betis but stayed up due to a superior head-to-head record. Sporting, Osasuna and Valladolid all ended on 43.
Earlier, a hat-trick from captain Raul Tamudo gave Espanyol a 3-0 win over eighth-placed Malaga to move the Barcelona-based club up to 10th.
It was Espanyol's eighth win in their last 10 matches, a run that saved them from relegation, and the final game at the Olympic Stadium before their move to Cornella-El Prat.
Sevilla, assured of third place and a spot in next season's Champions League, won 2-0 at Numancia.
Treble winners Barcelona ended the season with a 1-1 draw at Deportivo Coruna on Saturday which took them to 87 points from 38 matches, their highest ever tally.
They also scored their most ever goals in a season and with 105 fell just two short of Real Madrid's record of 107 in 1989-90. Real finished on 78 points in second and Sevilla on 70.
Atletico Madrid's 3-0 home win over Almeria on Saturday secured them a Champions League qualifying place and Villarreal (fifth), Valencia (sixth) and King's Cup runners-up Athletic Bilbao go into the new Europa League.