A combative first half saw the visitors put Madrid under pressure, although the best chance fell to Vinicius Junior, sliding in to connect with Ferland Mendy's cross only to be denied by a full-stretch save by keeper David Soria.
After the break, Luka Modric shot just wide and then Dani Carvajal was brought down inside the Getafe box for Ramos to step up and score his ninth league goal this season and fourth since La Liga restarted.
Playing against Getafe -- an aggressive, well-organised side with Champions League aspirations under coach Jose Bordalas -- is no fun at all. Real Madrid's players refused to be bullied, though, ensuring they gave as good as they got and picking up five yellow cards in the process. When Getafe finally dropped off physically, Madrid's quality and options off the bench saw them seize the advantage.
The result means Real Madrid maintain their 100 percent record in this final stretch. It feels very, very unlikely that a stuttering Barca will overhaul this four-point lead at the top of the table now with five games to go.
Too often the pattern of this match followed Getafe's game plan, not Real Madrid's. There was little opportunity for flowing football, and Zinedine Zidane's team struggled to impose themselves for long spells. Ultimately, though, it was all about the three points.
Madrid will be hoping that Raphael Varane's first-half substitution -- he left feeling dazed and dizzy by a ball to the face -- was merely a precaution and that he'll be available for Sunday's game at Athletic Bilbao. Deputy Eder Militao is not of the same standard.
Manager rating out of 10
8 - Zinedine Zidane made three changes to the team that won 1-0 at Espanyol on Sunday, with Mendy and Modric returning from suspension and Vinicius replacing Eden Hazard, who was left out of the squad entirely.
The inclusion of four midfielders was the right call, and recognition of the need to win the midfield battle. Zidane's decisive triple substitution with half an hour to go was spot on too, as Marco Asensio, Rodrygo and Fede Valverde gave the team a much-needed energy boost.
Player ratings (1-10; 10 = best. Players introduced after 70 minutes get no rating)
GK Thibaut Courtois, 7 - The busier goalkeeper early on, making one especially good stop from a deflected header. A much quieter second half.
DF Dani Carvajal, 8 - Relishes this kind of game. Picked up an early yellow card for taking out Marc Cucurella, and had enough energy later on to race into the box and win the penalty kick.
DF Sergio Ramos, 8 - Appears to be enjoying every moment of this condensed season finale. Still getting forward to attack at every opportunity and scored the winning goal with a cool finish from the penalty spot.
DF Raphael Varane, 6 - Lasted just half an hour before being withdrawn after catching an unexpected ball to the face in an aerial challenge.
DF Ferland Mendy, 7 - Created Madrid's best first-half chance, bursting down the left and delivering a pinpoint low cross for Vinicius.
MF Casemiro, 7 - A very busy evening all over the pitch. Had a first-half penalty appeal denied, the challenge coming just outside the box.
MF Toni Kroos, 7 - Denied space by Getafe's midfielders as they looked to disrupt Madrid's passing game. Grew in influence in the second half.
MF Luka Modric, 7 - A clever pass released Mendy in Madrid's best moment of the first half. Booked for a stamp on Jaime Mata, and went close to scoring with a low shot before being substituted.
MF Isco, 6 - Caught by Getafe's David Timor with a bad foul inside the first 10 seconds of the game and had one early half chance. Sometimes wanted more time on the ball than the visitors were ever going to allow.
FW Vinicius Junior, 6 - The teenager was unlucky not to score in the first half when he got on the end of Mendy's cross only to be denied by Soria. Quiet after that, and taken off after an hour.
FW Karim Benzema, 6 - Didn't get much service, denied space and often found himself a long way from goal looking for the ball.
DF Eder Militao, 5 - Unexpectedly called into action early when Varane needed to come off. Yellow carded for a wild tackle on Cucurella, and occasionally got his team into trouble.
FW Marco Asensio, 7 - Looked bright, finding Benzema inside the box with a cross five minutes after coming on.
MF Fede Valverde, 6 - Brought on to offer more bite and legs to Madrid's midfield.
FW Rodrygo Goes, 6 - Came on for Isco and didn't make much impact.
FW Mariano Diaz, NR - Replaced Benzema in added time.