Messi came early to the home owner after a neat pass from Sergio Busquets, but Getafe equalized when Climo Lingley struck home by mistake.
The visitors’ net was conceded by defender Sufyan Shakla, who passed a ball to the back that deceived goalkeeper David Soria.
Messi strengthened Barcelona’s progress before the end of the first half to raise its score to 25 goals in the league this season, but the Catalan team retreated in the second half and Turkish striker Ines Unal reduced the difference from a penalty kick that interfered with the video referee to be counted in the 69th minute after a mistake on defender Ronald Arajo.
The Uruguayan defender made up for his mistake when he converted Messi’s corner kick into the net in the 87th minute.
Antoine Griezmann finished off with a penalty in stoppage time after Messi preferred the French player to take the kick instead.
In another match, Atletico Madrid strengthened their position in the race for the LaLiga title with a 2-0 win over struggling Huesca after being netted in each half by Angel Correa and Yannick Carrasco.
Atletico Madrid tops the standings with 73 points after 32 games, three points ahead of Real Madrid, who beat Cadiz 3-0, while Barcelona are third with 68 points.