Messi double saves Barcelona
Barca appeared set for their first defeat under coach Tito Vilanova, who was sent from the dug-out for complaining to the referee midway through the second half, before Messi came to the rescue.
Osasuna was the scene of a Barca defeat last season that helped to turn the title race against them and they went behind this time after a 17th-minute goal from Joseba Llorente.
After the visitors missed a hatful of opportunities, the game appeared to be going against them, until Messi rose to the occasion with strikes after 75 and 80 minutes.
Osasuna's Francisco Punal was red-carded by the referee for protesting about the Argentine's first strike, as he felt he was offside.
Victory provisionally took Barcelona top of the early-season standings, above Rayo Vallecano on goal difference.
Barca now turn their attention to the second leg of the Spanish Super Cup on Thursday, when they face Real Madrid at the Bernabeu with a 3-2 lead.
Madrid play derby rivals Getafe later on Sunday.
Barcelona goalkeeper Victor Valdes prevented Osasuna from taking the lead inside the first minute as he palmed away a close-range effort from Alvaro Cejudo, who had easily skipped past Gerard Pique.
Then, at the other end, Andres Fernandez got down well to claw away a shot from Alexis Sanchez.
Osasuna, who lost at Deportivo La Coruna last weekend, aimed to hustle Barca out of their stride but the Catalans began to find openings, with Andres Iniesta firing over and Cristian Tello hitting the post from 25 yards.
However, it was with the visitors in the ascendancy that Osasuna snatched the lead on the break.
Roland Lamah sent a deep cross from the left wing that found Llorente -- on loan from Real Sociedad -- and he squeezed the ball in at the far post.
Barcelona responded, with Tello forcing another save out of Fernandez and Iniesta blazed over with the goal gaping, but at the back they looked hesitant and uncertain.
Centre-backs Carles Puyol and Pique failed to communicate as Lamah bundled through and was denied by Valdes, before a follow-up strike from Llorente was charged down.
Messi and Iniesta failed to convert further chances before the break and then after the restart the game became cagey as Osasuna gave Barca little space to play in.
The game appeared to be going away from Barcelona but Messi popped up with two goals in the last 15 minutes to rescue them, first touching in a Sanchez cross and then finishing clinically with his left foot to condemn Osasuna.
Madrid are unbeaten in the league in 2012 after a stunning march towards last season's league title, but they are searching for their first win of this campaign as they could only draw 1-1 at home to Valencia in their opening game.
Also on Sunday, Granada face Sevilla and Valencia entertain Deportivo.
Related Barcelona News