The best chance for Real in the first half came from Vinicius Junior, but his swift poke from right in front of goal was parried away by Getafe keeper David Soria to keep the things level in a scoreless opening 45 minutes.
It was more of the same in the second half as the hosts struggled to find a crucial go-ahead goal and were bailed out when Dani Carvajal was fouled in the penalty area in the 78th minute.
Sergio Ramos stepped up and calmly converted the spot kick — his ninth goal of the season — sending Soria the wrong way to put Madrid in position to see out the game.
The late strike felt harsh on Getafe, who had squandered a couple of chances to take the lead, but Zinedine Zidane’s side once again saw out a difficult game to capitalise on Barca’s 2-2 draw with Atletico Madrid on Tuesday.
Real Madrid have now recorded 17 clean sheets in league play this season, their most in a single campaign over the last 20 years.
The result means Real now lead Barcelona by four points in La Liga with five matches left to play in the 2019-20 campaign.