Real Madrid were forced to settle for second in LaLiga despite coming from behind to beat Villarreal as city rivals Atletico did likewise at Real Valladolid to claim a first top-flight title in seven years.
The defending champions had to win their final match of the season and hope for a slip at the last by Atletico, who fell behind early on but rallied in the second half courtesy of goals from Angel Correa and Luis Suarez.
Atletico's result meant what happened at the Estadio Alfredo Di Stefano was irrelevant in the context of the title race, but Real ended their campaign with a flourish as Karim Benzema and Luka Modric struck late on for a 2-1 win.
Victory for Los Blancos seemed unlikely for much of the contest, with Yeremi Pino giving the visitors the lead after 20 minutes, coolly flicking beyond Thibaut Courtois with the outside of his right boot.
Villarreal face Manchester United in the Europa League final on Wednesday and, had they held on against Real, they would have guaranteed a return to that competition next season, but their seventh-place finish means as things stand they will play in the Europa Conference League play-off round.
The referee was uninterested in Real's pleas for a penalty after the ball seemed to brush Daniel Parejo's hand in the area, while Modric missed the target and Casemiro shot straight at Geronimo Rulli before half-time.
Benzema thought he had levelled after heading home Casemiro's cross but the goal was chalked off because the Frenchman had strayed offside. At roughly the same moment the goal was disallowed, Correa equalised for Atletico.
Suarez then put Atletico ahead midway through the second half at the Estadio Jose Zorrilla as Real sent on Isco and Rodrygo on the outskirts of the Spanish capital in a bid to get back into their match.
Benzema gave them hope three minutes from time with a fine curled finish into the roof of the net after collecting a short pass from Rodrygo, who had darted to the edge of the box from the right wing.
And in the second minute of time added-on, Modric chested down Benzema's cross from the left side of the area before slamming into the roof of the net. But Atletico held on as they ensured they finished two points ahead of Real at the top.