Real Sociedad fell to a 2-1 defeat at Atletico Madrid on Sunday but still sealed qualification for next season's Champions League after Villarreal were beaten 2-1 at Rayo Vallecano.

Imanol Alguacil's Basque outfit finished fourth in La Liga despite defeat only thanks to Villarreal losing too.

Espanyol were relegated from the top flight after Valencia's Samuel Lino struck a stoppage-time equaliser in a gripping 2-2 draw.

One other side will go down along with already-relegated Elche on the final day of the season, with Real Valladolid currently 18th, a point from safety, after they drew 0-0 at Almeria.

Celta Vigo lost 1-0 at Cadiz and are 17th, a point from safety, along with Almeria.

Antoine Griezmann and Nahuel Molina struck for Atletico in their win over Real Sociedad, who struggled to create much of note, perhaps aware of Villarreal's struggles.

Eventually Alexander Sorloth pulled one back for the visitors at the Metropolitano to give them something to celebrate as they achieved their European goal.

"I would have liked to be able to celebrate qualifying another way, but we have had a great season and are very happy," Real Sociedad striker Mikel Oyarzabal told Movistar.

"We have to celebrate, the fans should enjoy it, and next Sunday we can have a party at home, a celebration -- we'll do all we can to win that game and end things well."

Victory leaves Atletico third, a point behind Real Madrid.

Raul de Tomas and Isi Palazon netted for Rayo against Quique Setien's side, who pulled a late goal back through Giovani Lo Celso, but could not turn the game around.

Villarreal will play in the Europa League next season, along with Real Betis, sixth, who beat Girona 2-1.

Osasuna, who fell to a late 2-1 defeat by Getafe which took the Madrid side two points clear of the relegation zone, are seventh and currently in line to qualify for the Conference League.

However Athletic Bilbao, Girona, Rayo and Sevilla remain in contention for the spot.