Santi Cazorla's stunning free-kick in the last minute punished Real Madrid as Malaga held them to a 1-1 draw after Karim Benzema's opener.
Iker Casillas and Willy Caballero made smart stops to deny Salomon Rondon and Cristiano Ronaldo within the first five minutes but after Isco had missed another good chance for the visitors it was Real who went in front as Ronaldo's cross found Benzema free at the back post to head home.
Caballero made another brilliant save to deny Ronaldo doubling Madrid's advantage early in the second-half, but the hosts struggled to kill the game off and that proved costly.
Cazorla curled in a wonderful 25-yard free-kick into Casillas' top corner in the 91st minute to halt Real Madrid's 11-match winning run in the Primera Division.
Roberto Soldado scored a hat-trick as Valencia strengthened their position in third place with a commanding 3-0 win over Athletic Bilbao at San Mames.
The Spanish international took advantage of a weak backpass from Mikel San Jose to round Gorka Iraizoz and put the visitors in front just before half-time, and he doubled Valencia's lead 12 minutes after the break with another excellent finish from Jordi Alba's cut-back.
Andoni Iraola was then sent off for the hosts for a second bookable offence when he brought down Alba, and Athletic's misery was complete with five minutes to go when referee Fernando Teixeira Vitienes awarded a harsh penalty for a handball by San Jose and Soldado confidently stroked home from the spot.
Xavi Torres scored the winner deep into stoppage-time to condemn Villarreal to their fourth defeat and five games and boost Levante's hopes of a top-four finish with a 1-0 victory.
Neither side created many chances, but both had goals ruled out in the second half as Torres was adjudged to be just offside as he headed in, while at the other end Nilmar thought he had scored a bizarre winner, but was instead booked for flicking the ball out of Gustavo Munua's hands before tapping into an empty net.
However, in a dramatic finale Carlos Marchena was sent off for a second yellow card for a foul on Valdo and from the resulting free-kick Ruben Suarez's effort struck the inside of the post and left Torres with the easiest of finishes to slot home his third goal of the season.
Ten-man Real Mallorca brought Atletico Madrid back down to earth with a bump today with a 2-1 victory in an eventful match at the Iberostar Stadium.
The visitors had celebrated progression through to the last eight of the Europa League in midweek, but a Diego Godin own goal and Michael Pereira strike left them trailing to Mallorca.
The dismissal of Ivan Ramis gave Atletico hope of a comeback, but a missed penalty from Falcao proved costly with his later goal not enough to rescue Diego Simeone's side.