Second-placed Atletico Madrid, who sit between the two giants at the top of the league, lost ground losing 3-0 at Athletic Bilbao.
Atletico's defeat means Barcelona stretch the lead to 11 points at the top, while Real are only four behind their city rivals in third place.
Mikel San Jose headed the first of the game from a corner on 50 minutes for Athletic Bilbao who move into 12th.
Markel Susaeta doubled the lead on 77 minutes, finishing well after running onto a delightful through ball from Ander Herrera.
The third was again superb counter-attacking play from the Basques when Oscar De Marcos finished off a crisp passing move.
Messi earlier became the first player to score in 11 consecutive La Liga matches when he hit four as Barcelona eased past 10-man Osasuna.
Osasuna remain in the relegation zone on 18 points, two from safety.
Messi has 33 goals for the season, 12 more than Ronaldo.
It only took 11 minutes for Messi to open the scoring and claim another record.
A long through pass was cleared by Andres only as far as Xavi Hernandez, who found the Argentine in the area, Messi then producing a beautiful dummy to take him past the 'keeper before tapping home.
Raoul Loe levelled the game on 24 minutes against the run of play, but the side from Pamplona were left with 10 men three minutes later when centre-half Alejandro Arribas received a second yellow card after a shot struck his hand in the area.
Messi coolly slotted away the penalty for his second and Pedro Rodriguez made it three before halftime after a generous pass from Dani Alves left him with a tap in from close range.
The Argentine recorded his hat-trick on 56 minutes when he started a move in midfield, exchanged passes with Villa, and took the ball around the keeper before slotting home.
And a minute later, it was five as he finished off a swift Barca attack and Adriano pass from close range.
All Real's goals came in a much improved second-half performance in the derby against Getafe.
Sergio Ramos scored the first before Ronaldo hit three in 10 minutes, his first on 62 minutes after a sweeping counter-attack in which Mesut Ozil played the Portuguese star into space on the left for a crisp finish.
Three minutes later, he finished off a Gonzalo Higuain cross with a simple header and completed his hat-trick from the penalty spot after Alberto Lopo had fouled Luka Modric.
Also on Sunday, Malaga moved into fourth with a 3-2 win at Mallorca, and Rayo Vallecano beat Real Betis 3-0 to move into sixth, a place and a point behind the Seville-based side.