Barcelona appeared set for their first defeat under coach Tito Vilanova, who was sent from the dug-out for complaining to the referee, before Messi came to the rescue.
The visitors, who were guilty of missing a host of chances, went behind after a 17th minute goal from Joseba Llorente.
Osasuna’s Francisco Punal was also given his marching orders as Barca pounced on the numerical advantage with Messi strikes in the 75th and 80th minutes to claim the points.
Victory has provisionally taken Barcelona to the top of the early-season standings, above Rayo Vallecano on goal difference.
Real Madrid let a first-half lead slip at the hands of Getafe, who came away 2-1 victors.
Gonzalo Higuain netted in the 27th minute from a tight angle but Jose Mourinho’s men failed to stop Juan Valera from equalising.
Abdelaziz Barrada later capitalised on a Raul Albiol mistake to claim their first win of the season, as Madrid slumped to 15th in the table after two games.
Granada found themselves a man down when Inigo Lopez was given a red card for a foul in the box but came away with a point at home to Sevilla.
Guillherme Siqueira had his spot-kick saved before Mikel Rico netted for the hosts. Alvaro Negredo replied on the stroke of half-time for the visitors.
Valencia and Deportivo were a late kick-off (10pm).