Barcelona's loss at Osasuna's Reyno de Navarra Stadium last season played a part in the Catalan club losing the title to Real Madrid, and the hosts looked destined for another win after Joseba Llorente's acrobatic 17th-minute goal.
But even after Osasuna striker Juan Francisco Martinez hit the post and Barcelona coach Tito Vilanova was sent off, Barcelona rallied as Messi guided Alexis Sanchez's short pass beyond goalkeeper Andres Fernandez to equalize in the 76th minute.
Osasuna went down to 10 men when Francisco Punal was red carded for arguing the goal was offside.
Messi then latched on to Jordi Alba's cross in the 80th for the winner and his league-leading fourth goal, giving Barcelona its first come-from-behind victory from a halftime deficit in Pamplona since 1960.
Barcelona joined Rayo Vallecano with six points. Madrid can trim the gap to two points with a victory at crosstown rival Getafe in its second-round match later Sunday.
Osasuna looked on course for another victory over the Catalans after a confident start, resulting in Llorente getting his right foot at chest level to tap Roland Lamah's cross past goalkeeper Victor Valdes at the near post.
Valdes had come under fire following a poor performance in a 3-2 Spanish Super Cup win over Madrid last week, but was steady throughout Sunday. He made saves to deny Alvaro Cejudo in the opening moments and against to block from Martinez, who also hit the post with only the `keeper to beat after dispossessing Sergio Busquets.
That play elicited a reaction from Vilanova, who was sent off in his third official game in charge, and from the visitors.
Fernandez saved from Barcelona pair Andres Iniesta and Messi, with Barcelona's attack only awakening after the introduction of Xavi Hernandez off the bench for Iniesta in the 70th. Cesc Fabregas has started in place of the midfield maestro but failed to guide the team with any distinction.
Fernandez watched in exasperation as Messi's redirected shot crossed the goal line to undo the hosts' momentum.
Barcelona immediately took advantage of the extra space with the man advantage, Alba guiding in a long cross from the left straight for Messi to curl home the winner.
In other matches later Sunday, Granada plays Sevilla and Deportivo La Coruna is at Valencia.