The Argentine's stunning free-kick gave Pep Guardiola's men all three points against a well-drilled Atleti team to once again close the gap on their bitter rivals
Dani Alves scored the opening goal of the game in the 36th minute as the visitors looked good value for their lead at half-time, yet Radamel Falcao grabbed a leveller four minutes after the restart.
Messi came to the rescue in the 81st minute with a stunning free-kick to give Barca all three points against their unfortunate opponents, who competed well throughout.
Barcelona looked lively in the opening stages and thought they had opened the scoring in the eighth minute, only for the effort to be disallowed.
Lionel Messi controlled Alexis Sanchez' pass before bypassing two Atletico defenders and pushing the ball past Thibaut Courtois. However, the Argentine was ruled to have used his hand to control the ball in the build-up, earning himself a yellow card in the process - his fifth this season, meaning he will miss the side's game against Sporting next weekend.
The reigning Liga champions came close again on 20 minutes through a well-taken set-piece. Xavi stepped up to curl a free-kick 25 yards from goal, but the Atleti goalkeeper was on hand to make a strong acrobatic save to deny the away team the opener.
Both teams were difficult to separate in the first period, yet the visitors did take the lead in the 36th minute after a smart team move. Dani Alves linked up well with Messi before the attacker slid the ball to Cesc Fabregas to fire across the six-yard line, with Alves waiting to score his second league goal of the campaign.
However, two minutes after taking the lead, Guardiola's men had Victor Valdes to thank for preserving their narrow advantage. After some sloppy defensive play from the visitors, Arda Turan broke into the box before slamming across goal, with Falcao lurking, yet Valdes was sharp enough to intercept.
Atletico made a superb start to the second period and grabbed an equaliser in the 49th minute. Gabi's corner was unintentionally flicked towards the back post by Sergio Busquets and an unmarked Falcao was waiting to volley home from six yards, his 20th goal this term in all competitions.
Barcelona were then fortunate to be given the benefit of the doubt from the assistant referee on two questionable offside calls, and despite not looking anywhere near their best in the second half, the away side did come within inches of retaking the lead on 67 minutes. Alves' inviting cross was narrowly missed by Messi at the front post yet Alexis Sanchez was on cue to head the ball over the bar from close range.
Just when it appeared Barcelona would have to settle for a point, Messi stepped up with a true moment of magic. The Argentine's free-kick fooled everyone as it curled into the far corner from 25 yards out with Courtois left rooted to his spot - the attacker's 28th Liga goal of the season and arguably his most important.
Valdes had to look sharp near the end to preserve his side's advantage, blocking from Juanfran and Adrian, and in the end Barca were relieved to hear the final whistle and collect the victory.
Next up for Barcelona is a home encounter against Sporting next weekend, while Atletico face a trip to Sevilla, hoping to return to winning ways.