Madrid fell behind to a deflected goal by Angel Lafita after five minutes, but Pepe equalised a quarter of an hour later.
Cristiano Ronaldo then put Madrid ahead from the penalty spot before Isco extended Madrid's advantage with a goal in the second half.
Getafe midfielder Michel, who had given away the penalty, was sent off for a second bookable offence with eight minutes remaining and then in the final minute of stoppage time Ronaldo added his second goal of the night, his 208th for Los Blancos, which meant he unseated former Mexico striker Hugo Sanchez as the club's fifth top goalscorer of all time.
Real coach Carlo Ancelotti said: "Overall, the team played well for 90 minutes. We were unlucky with Pepe's deflection putting us behind, but the reaction was very good. In the first half we did not play very quickly, but in the second, with more space, the match was easier and we had lots of chances."