Ronaldo had his powerful shot parried away by Vincente Guaita after being set up by Karim Benzema in the 11th minute.
After 39 minutes Benzema scored as Real went on the counter before the striker drove a well-placed shot into the back of the net,1-0.
Six minutes into the second half Marcelo unleashed a volley towards goal which marginally missed the target.
Getafe then found the equaliser against the run of play as Jorge Molina rounded off a counter attacking move after 56 minutes, 1-1.
Ronaldo missed a perfect opportunity to regain Madrid's lead when he fumbled a tap-in with an open goal at his mercy with 17 minutes left on the clock.
Five minutes from time, Ronaldo made up for the earlier miss when he volleyed home after getting on the end of Isco's through ball to make it 2-1.
Real shot-stopper Kiko Casilla almost handed Getafe the equaliser after his punch fell for Medhi Lancen, whose shot flew inches wide as Real held on to claim three points.