Imanol Alguacil's side reached Europe's premier competition for the first time since 2013 as the Yellow Submarine's slip-up at Vallecas ensured the Basque club finish fourth.
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.
"To get to this situation we have done many things wrong, but I think sincerely, from the most self-critical position personally and as a group, that we don't deserve this in this way," Espanyol midfielder Sergi Darder told 'Movistar'.
"Above all, we want to say sorry. We have such a big club badge that in many moments, we haven't represented. I'm the first to be angry, but have no doubt we will be back."
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 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.
May 28, 2023
Elsewhere in the league, Celta Vigo lost 1-0 at Cadiz and are 17th, a point from safety, along with Almeria.
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.