Messi opened the scoring at Camp Nou in the eighth minute just moments after hitting the bar. Getafe levelled almost immediately when Clement Lenglet turned into his own net but Sofian Chakla's own goal at the other end restored Barca's lead just before the half-hour mark. Messi added his second, his 25th in the league this season, before the break.
Getafe set up a nervy final 20 minutes for Ronald Koeman's side when Enes Unal converted a penalty but Ronald Araujo, who gave away the spot kick, made amends by heading in Barca's fourth late on. Antoine Griezmann then won and converted a stoppage-time penalty to wrap up the points.
Barcelona are now within five points of leaders Atletico but have a game in hand -- and still play Atletico at Camp Nou on May 8.
Barca knew going into the Getafe game that if they win their final eight fixtures, including the potential pivotal clash with leaders Atletico Madrid, they will win the league. That number is now down to seven.
In Messi, they once again have the league's outstanding player and he's looked determined to drive Barca to what appeared an unlikely title at the turn of the year. In 2021, he has now scored 18 goals in just 15 league games, all while setting up another eight for his teammates.
Barca were penalised for sloppiness at the back. The first goal was an own goal but was also born from poor defending, albeit with Oscar Mingueza off the pitch at the time receiving treatment. Araujo's rash challenge then gave Getafe hope in the final straight, even if it ultimately came to nothing.
Manager rating out of 10
6 -- Koeman made just one change from the side that won the Copa del Rey last week, with Sergi Roberto replacing Sergino Dest, but made two changes at the break and two more in the second half. It took the life out of his team and they struggled to get going again once Getafe got back into the game.
Player ratings (1-10; 10 = best. Players introduced after 70 minutes get no rating)
GK Marc-Andre ter Stegen, 6 -- Could do little about the two goals he conceded.
DF Oscar Mingueza, 7 -- Shook of an early knee injury to produce a decent performance, which made Koeman's rant at him in the second half and his subsequent substitution surprising. It seemed the Barca coach had not been happy about him pushing forward and leaving gaps behind.
DF Gerard Pique, 6 -- Only played the first half as he continued his recovery from injury.
DF Clement Lenglet, 5 -- Had an unfortunate opening 12 minutes during which time he was harshly booked for a foul on Juan Antonio Iglesias before deflecting home Angel Rodriguez's strike for an own goal.
MF Sergi Roberto, 5 -- Came in for Dest to make his first start in La Liga since November. Looked off the pace, missing a header in the build-up to Getafe's first goal.
MF Frenkie de Jong, 7 -- The man for all occasions and every position, albeit not at the level of last weekend's Copa del Rey final. Started in midfield before playing on the left and then the right of the back three.
MF Sergio Busquets, 8 -- Played a glorious quarterback-like pass for Messi's first goal, which was one of many good passes he produced on the night. He's in really good form at the moment.
MF Pedri, 6 -- Has played in 46 of 47 Barca games this season but could perhaps do with a breather to keep him fresh for the run-in.
MF Jordi Alba, 6 -- Linked with Messi well and got forward as ever, although he wasn't as heavily involved as he has been at times this season.
FW Lionel Messi, 8 -- Took both his goals well, hit the woodwork twice and set up Araujo's goal. Could single-handedly lead Barca to the title.
FW Antoine Griezmann, 6 -- Worked hard and got his reward late on when he won and converted a penalty, generously handed to him by Messi who was on a hat trick.
DF Ronald Araujo, 6 -- Gave away the penalty but bounced back by heading in Messi's corner.
MF Ilaix Moriba, 6 -- Looked at home in the 45 minutes he was given and will benefit from more first-team action.
MF Francisco Trincao, 6 -- Has been restricted to a more limited role since Barca switched to a back three and looks a little bit rusty.
DF Samuel Umtiti, N/R -- Came on for Mingueza after Koeman's rant.