Messi gave the Catalans the lead in the 20th minute, tucking the ball into the net from a tight angle after his initial shot was saved by the legs of Getafe goalkeeper David Soria.
Uruguay striker Luis Suarez then doubled Barca's advantage in the 39th with a spectacular volley from outside the area, but Getafe hit back two minutes before the interval with a close-range finish from striker Jaime Mata after a splendid team move.
The Catalans are 10 points ahead of European champions Real Madrid, whose struggles continued with a 2-0 home defeat by Real Sociedad.
Getafe's Mata, who had an earlier first-half strike ruled out at 0-0 for an apparent foul by team mate Angel Rodriguez, missed a big chance in the second half, ballooning the ball over the bar with Barca's goalkeeper Marc-Andre ter Stegen stranded.
Ter Stegen then made a flying save to keep out a powerful header from Leandro Cabrera, while Soria was kept busy down the other end and did well to prevent both Messi and French defender Clement Lenglet from stretching Barca's lead.