The Argentinian added the finish following a slick one-two with Andres Iniesta to move clear in second on the Catalan club's list of all-time top goalscorers.
And he rounded off the scoring with a simple finish after Iniesta had produced an outrageous piece of skill and shot against a post.
Messi's two goals were his 195th and 196th in all competitions for Barca and took him ahead of Laszlo Kubala on the all-time list.
Xavi scored with a rare header in between times as Barca remained one point ahead of Real Madrid at the top of the Primera Division and winless Racing remained in the bottom three.
Barca went ahead in the 11 minute following wonderful interplay between Messi and Iniesta.
The Argentinian played in Iniesta down the right and the Spaniard squeezed a perfect pass with the outside of his foot back inside for Messi as he broke into the area.
The 24-year-old was outnumbered by a host of green shirts, but burst between two defenders, dummied goalkeeper Antonio Tono and slid the ball into the empty net.
He might have added another moments later, but his shot from David Villa's pull-back was deflected over.
The hosts did have a second in the 27th minute, though, as Pedro made ground down the left and swung in a cross for the unmarked Xavi to head past the helpless Tono.
Carlos Puyol somehow contrived not to make it three when Pedro's fierce cut-back found him just a yard from the line, but the defender did not have time to adjust his feet and the ball bounced off him and was hacked away.
Mamadou Kone had a rare sight of goal for Racing at the start of the second half, but Victor Valdes clawed away his left-footed shot.
But Barca continued to dominate possession, toying with their visitors as they threatened to cut them open at will.
They should have had a penalty when Messi produced a burst of speed and scythed into the area. He looked to be tripped, but the referee waved away his claims.
It mattered little as the hosts made it three in the 68th minute.
Even Messi would have been impressed with the way Iniesta took his team-mate's pass with his right foot, flicked the ball past his marker on to his left and then got a shot away from 12 yards.
The ball came back off the far post, but Messi followed up to knock home the rebound.
The Argentinian could have had a hat-trick soon after only to stroke his shot wide when well placed, but it could not distract from another glorious display.