Dani Alves scored the opening goal of the game in the 36th minute as the visitors looked good value for the lead at halftime, yet Radamel Falcao grabbed a leveler 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 its unfortunate opponent, which competed well throughout.
Barcelona looked lively in the opening stages and thought it 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 champion 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 visiting side 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 the narrow lead. After some sloppy defensive play by Barcelona, Arda Turan broke into the box before slamming the ball across goal with Radamel Falcao lurking, yet Valdes was sharp enough to intercept it.
Atletico made a superb start to the second period and grabbed an equalizer in the 49th minute. Gabi's corner was unintentionally flicked towards the back post by Sergio Busquets where an unmarked Falcao was waiting to volley home from six yards, his 20th goal this term in all competitions.
Despite not looking anywhere near its 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.
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 meters out with Courtois left rooted to his spot. It was the attacker's 28th Liga goal of the season and arguably his most important.
Next up for Barcelona is a home encounter against Sporting next weekend while Atletico faces a trip to Sevilla, hoping to return to winning ways.
Follow GOAL.COM USA on
For all the latest action, check out the Fox Soccer Plus FREE Trial