Real Madrid needed a late Casemiro goal to see off Las Palmas 2-1 after Willian Jose equalised Sergio Ramos' opener in the 87th minute at the Estadio de Gran Canaria.
Ramos had opened the scoring for Madrid halfway through the first half when he glanced home a corner from Isco, but Zinedine Zidane's men failed to impress and the home side got a number of chances to level the scoring.
They eventually equalised late on when Willian Jose found the net with a delicate finish after being set up by Momo.
There was more drama to come, though, as Casemiro headed in Jese Rodriguez's delivery to snatch all three points, before Madrid skipper Ramos was sent off for a second bookable offence.
Sevilla recorded an important 4-2 win over Villarreal to keep their Champions League hopes alive, with Unai Emery's side now trailing Marcelino's team by just five points.
Vicente Iborra opened the scoring for Sevilla in the 23rd minute, only for Cedric Bakambu to strike twice before the break to give Villarreal the lead.
Victor Ruiz's own goal restored parity, before a stunning Yevhen Konoplyanka strike and Jose Antonio Reyes' injury-time goal sealed a 16th consecutive home win in all competitions for Sevilla, who saw Ever Banega dismissed for a second yellow with 11 minutes remaining.
Valencia's struggles continued as they were beaten 1-0 by local rivals Levante, with Giuseppe Rossi scoring the only goal of the game to down Gary Neville's men.
In Sunday's other match, Athletic Bilbao comfortably defeated Real Betis 3-1 at San Mames, thanks in the main to Sabin Merino's double.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.