Casemiro spared Real Madrid's blushes against Las Palmas as he scored late on to claim a dramatic 2-1 victory at the Estadio de Gran Canaria.
Las Palmas appeared to have claimed a hard-earned point when Willian Jose netted a well-taken 87th-minute equaliser to cancel out Sergio Ramos' excellent first-half header.
But Madrid midfielder Casemiro had other ideas, as he headed Jese Rodriguez's corner beyond home goalkeeper Javi Varas just two minutes after Willian Jose's leveller to snatch all three points for Zinedine Zidane's side.
Madrid skipper Ramos was then sent off for a second bookable offence in an action-packed ending, but the visitors held on for a third-straight league win that puts them back to within four points of second-placed Atletico Madrid and 12 behind runaway leaders Barcelona.
Las Palmas should have gone ahead early on following some sloppy play from Luka Modric inside his own half, but Willian Jose failed to take advantage as Keylor Navas made a smart save.
Cristiano Ronaldo came close to opening the scoring midway through the first half after a quick Madrid counter, only to see his shot parried by Varas.
Madrid would grab the lead from the resulting corner, though. Isco curled in the set piece and Ramos beat his marker to the ball and glanced home his second goal of the season.
Ronaldo again came close on the half-hour mark when he saw his shot from just inside the area take a deflection before going narrowly wide.
Pedro Bigas wasted a chance to restore parity when he wildly volleyed over after a dangerous corner from the right shortly after Ronaldo's effort.
Alvaro Arbeloa nearly surprised Navas when he inadvertently directed a free kick toward his own goal, but the Madrid keeper was alert and prevented an equaliser.
The Costa Rica stopper was again called into action shortly when he was forced to rush off his line to deny Nili at the edge of the area.
Momo was next to try his luck for Las Palmas from an indirect free-kick inside the area, only for Navas to once more show his class with a fine save.
The home side pushed hard for a late equaliser and eventually managed to beat Navas in the 87th minute when Willian Jose found the net with a clever dinked finish.
Madrid were not to be denied, though, as Casemiro restored their lead two minutes later when he headed home, before Ramos was shown his second booking, meaning he will miss next weekend's clash with his former club Sevilla.