Two-time reigning champions Real Madrid relinquished their Primera Division crown to arch rivals Barcelona after slumping to defeat at Villarreal.
Lying eight points behind pacesetters Barca with three games remaining, Madrid needed to win at El Madrigal to keep the title race alive - at least until Pep Guardiola's men met Real Mallorca.
But goals from Robert Pires, Ruben Cani and Joan Capdevila canceled out efforts from Madrid duo Rafael Van der Vaart and Gonzalo Higuain to give Villarreal a much-needed boost in their hunt for a Champions League spot and hand Barca the title.
Knowing nothing but a victory would do if they were to delay Barca's title celebrations, Madrid started well enough and should really have taken the lead inside the opening four minutes.
A Van der Vaart corner was headed back into the danger zone by Javi Garcia and Gabriel Heinze, standing all alone in the six-yard box, should have done much better with his header, which ended up flying well wide.
Van der Vaart then tested home goalkeeper Diego Lopez with a curling free-kick, but that was about as good as it got for Madrid and they found themselves trailing by the 16th minute.
The 32-year-old Ariel Ibagaza created the chance as he made ground down the left before whipping in a cross, and the 35-year-old Pires finished the chance off with a thumping header from near the penalty spot.
With their already faint title hopes slipping further away, that goal seemed to knock the wind out of Madrid and they looked a side devoid of ideas for most of the remainder of the first half as Villarreal dominated proceedings.
Madrid coach Juande Ramos had seen enough and at half-time he replaced the ineffectual Klaas Jan Huntelaar with top scorer Gonzalo Higuain, and the move paid almost immediate dividends.
A deep cross from Miguel Torres picked out Higuain at the far post and the Argentinian's first-time pass across the face of goal allowed Van der Vaart the easiest of tap-ins as the Villarreal defense was nowhere to be seen.
That was inside the opening minute of the second half and was just the boost Madrid needed following a disappointing first half.
However, the visitors could not build on that and Joseba Llorente and Capdevila both went close for Villarreal before the hosts re-took the lead in the 62nd minute through Cani.
Madrid center-back Fabio Cannavaro's attempt at cutting out a cross saw the ball fall kindly into the Cani's path and the number 10 lashed a first-time shot past Casillas.
That left Madrid with a huge mountain to climb and it really should have been curtains for the capital club when Capdevila struck the crossbar from virtually on the line following a low Giuseppe Rossi free-kick.
Madrid enjoyed a let-off on that occasion, and then again in the 84th minute when Villarreal striker Nihat Kahveci saw his goal celebrations cut short by an offside flag, and Ramos' men then gave themselves a lifeline when Higuain netted in the 88th minute.
Higuain looked to be standing well offside when he picked up Raul's half-blocked shot, but the flag stayed down and the young striker slotted past Lopez.
There was to be no fairytale finale for Madrid though as two minutes later Capdevila scored the goal that finally ended their title hopes.
Casillas made a mess of trying to catch Nihat's corner, and Capdevila could barely believe his luck as the ball dropped at his feet and all he had to do was poke it over the line.