The Catalans created little in one of their worst first-half displays at the Camp Nou this season but found a breakthrough early in the second when Martin Braithwaite released Messi with a classy backheel and the Argentine did the rest.
Barca, who failed to hold onto a narrow lead in Sunday's 1-1 draw at home to Cadiz, got an all-important second goal in the 69th when Frenkie de Jong received the ball after some clever play from 18-year-old Pedri.
The Dutchman burst through the middle of the pitch and laid the ball off for Messi to dribble into the net for an 18th league goal of the season, extending his lead at the top of the scoring charts.
Left back Jordi Alba struck the third goal from another Braithwaite assist to round off a victory which took Barca back above Sevilla and into third in the standings on 50 points, five behind Atletico but having played a game more.
Sunday's frustrating draw at home to Cadiz had interrupted a seven-game winning streak in the league and added to the pain of last week's 4-1 routing at home to Paris St Germain in the Champions League.
"This will help our confidence a lot," said Alba.
"The draw [with Cadiz] was a huge blow to the whole team and showed that if we are not at our 100% best we find it very hard to win. We struggled on Sunday and in the first half here too but we were better in the second and the goals arrived."
Barca looked shaken by their recent form in an insipid first half in which they were fortunate not to fall behind when Argentine forward Lucas Boye caught a clear sight of goal inside the area but blasted over the bar.
Portuguese winger Francisco Trincao was Barca's liveliest player in the first half and was twice denied by Elche keeper Edgar Badia, who also did well to keep out a header from De Jong, with Alba somehow missing the target on the rebound.
Barca regained their composure after the break and opened the scoring thanks to clever combination play between Braithwaite and Messi but were let off the hook moments later when Boye again missed the target.
Messi's second goal calmed their nerves and they were hungry for more even after Alba's strike.
Substitute Antoine Griezmann hammered the crossbar from just inside the area and then missed the target from an even easier position moments later, the twin misses summing up the France's striker's low levels of confidence.