The penalty was Messi's 200th career Spanish league goal, making him the eighth player to reach that mark and the youngest ever by four years at 25 years old.
After Messi had hit the post with a header, Pedro Rodriguez finished off a pass from Dani Alves to make it 3-1 in the 40th from another move started by Xavi.
David Villa then participated in Messi's goals in the 56th and 58th, first working a one-two combination with the four-time world player of the year for him to score from an angle. Villa then made a back pass that Adriano sent on to Messi, who tapped in his fourth goal of the night.
Earlier, Sergio Ramos scored Madrid's first goal in the 53rd minute after fellow defender Ricardo Carvalho forced goalkeeper Miguel Moya to fumble the ball by hitting his arms in an apparent foul that went unpunished.
"It was clearly a foul," Getafe coach Luis Garcia said. "It's a pity. When you are losing you have to push forward, and that's what let them get out on the break. Madrid is the best team in the world on the counterattack."
Ahead 1-0, Madrid didn't look back.
Ronaldo finished off a counterattack from its own area in the 62nd, running onto Mesut Oezil's pass and firing the ball beyond Moya.
Three minutes later, Ronaldo made it 3-0 as he charged in unmarked behind Gonzalo Higuain to head home Di Maria's floated cross at the far post. He then dispatched a penalty kick into the lower left corner in the 72nd after Alberto Lopo fouled Luka Modric in the box.
"I'm satisfied with (my hat trick), but my task is to keep it up and give my all for this club," said Ronaldo. "I want to surpass my own personal record from last season."
The Portugal forward, rarely substituted, was taken off seconds later to the applause of the Santiago Bernabeu crowd.
Outpatient ROBOTIC HYSTERECTOMY. Trust an experienced Robotic Surgeon.