La Liga: Lionel Messi hits 4, Cristiano Ronaldo passes 300 goals
Real struggled to break through a determined Getafe defence in the first half but once Ramos had scrambled the ball into the net from a corner eight minutes after the break the home side turned the screw.
Ronaldo struck three times in 10 minutes, the first his 300th club goal.
The Portuguese, who was substituted with 15 minutes left after a knock to his right ankle, scored five for Sporting Lisbon, 118 for Manchester United and now has 179 for Real thanks to his 20th career treble.
Real centre back Ricardo Carvalho appeared to impede Getafe goalkeeper Miguel Angel Moya with his arm in the leadup to the opening goal.
"It was a very quick passage of play for the Ramos goal and I don't know if it was a foul or not," Portuguese Carvalho said.
"The important thing was to win in that way so we can be stronger for the Cup and the Champions League."
Getafe, who beat Real 2-1 at their Coliseum stadium earlier in the season but whose form has dipped in recent weeks, are 11th on 26 points, one ahead of Bilbao.