Racing Santander 1 - 2 Barcelona
Racing gave the visitors little space and took the lead after the restart when Nikola Zigic scored from the penalty spot.
Messi's introduction galvanised Barca and the Argentine stole in to score the equaliser within 10 minutes of coming on the pitch, and grabbed the winner nine minutes from time.
Barca, who had Rafael Marquez and Gerard Pique sent off in the closing minutes, restored their 12-point lead at the top of the table.
Champions Real Madrid, who beat Numancia 2-0 away on Saturday, are second.
Third-placed Sevilla, on 38 points, visit Sporting Gijon later on Sunday when Valencia, in fourth, host Almeria.
Villarreal stay fifth with 34 points after falling 3-0 away to Deportivo Coruna, who climbed to sixth.