The Portugese midfielder headed the decisive goal with a minute remaining, two minutes after Willian Jose had equalised for the hosts.
Captain Sergio Ramos had given Real Madrid the lead in the first half, but was later sent off.
Victory leaves third-placed Real four points behind Atletico Madrid in second and 12 behind leaders Barcelona.
Real were frustrated for much of the first half by determined Las Palmas defending, but the hosts could not stop Ramos opening the scoring in the 24th minute.
The defender met Isco's corner and glanced a header past goalkeeper Javi Varas.
Willian Jose levelled for the hosts with three minutes remaining after Real squandered possession from a free-kick, but the visitors responded immediately as Casemiro headed home a corner.
Ramos was sent off in stoppage time after picking up a second yellow card.
Real Madrid survived a scare to beat Las Palmas through Casemiro's late winner.