The World Player of the Year pounced on a loose ball to level in the 50th minute before netting a superb free-kick for the winner in the 73rd, the 37th goal of the campaign for La Liga's top scorer.
Only a last-minute save from keeper Tono in a one-on-one situation denied Messi a hat-trick.
The victory moved Barca 15 points clear at the top of the table.
"Over 300 goals. It's extraordinary what Messi does," Barca assistant coach Jordi Roura told a news conference.
"We had a lot of chances and didn't take them but he got two goals that are very important."
Javier Saviola scored the only goal as Malaga warmed up for their midweek Champions League tie with a 1-0 home win over mis-firing Athletic Bilbao.
The Qatari-owned club from the Costa del Sol, in their debut Champions League venture, visit Porto in a first leg tie on Tuesday.
Argentine Saviola's seventh league goal of the season gave the hosts an 18th-minute advantage. The safe hands of compatriot, goalkeeper Willy Caballero, then helped preserve the lead as fourth-placed Malaga moved on to 42 points, four behind Real Madrid.
Getafe made light work of La Liga's worst travellers Celta Vigo, romping to a 3-1 victory with all the goals coming in the first half.
An early header from Kike Sola gave Osasuna a 1-0 home win over Real Zaragoza in a scrappy late game littered with yellow cards.
Barca travelled to Granada without Xavi and David Villa and started with Andres Iniesta, Jordi Alba and Carles Puyol on the bench.
The hosts have been lifted by the arrival of new coach Lucas Alcaraz, winning their first two games under him without conceding a goal.
Granada defeated Real 1-0 two weeks ago, when Cristiano Ronaldo headed an own goal, and downed Deportivo La Coruna 3-0 last time out.
Striker Odion Ighalo put them in front from close range after 26 minutes and they held Barca at bay until just after the restart when Messi reacted quickly after Tono could only parry a Cesc Fabregas shot.
The Argentine added a second goal when his free-kick over the wall was too strong for Tono who got a hand to the ball. Barca then had to endure a shaky last few minutes with Victor Valdes pulling off two late saves.
"These are the most important games because people write them off and they turn out to be the ones that win you La Liga," said Spain midfielder Fabregas.
Malaga took the game to Bilbao at the Rosaleda and loan signing from Chelsea, Lucas Piazon, set up the goal for Saviola when he dribbled to the byline and pulled the ball back for the striker to score.
Piazon and Isco were a constant threat in midfield but Malaga were sloppy in defence at times and Caballero had to make a number of sharp saves to deny Bilbao.
Get the best features, fun and footballing frolics straight to your inbox every week.
Thank you for signing up to Four Four Two. You will receive a verification email shortly.
There was a problem. Please refresh the page and try again.