Barca are aiming for their third Champions League trophy in five years but could have had their first home defeat in the competition in nearly three years when Romulo gave the visitors the lead on the hour mark.
The hosts have made a blistering start in La Liga with four straight wins and went ahead early on through Cristian Tello, but an own-goal from Dani Alves after 29 minutes brought Spartak back into the contest.
Barca were enjoying the vast majority of the play but Romulo's second-half goal left them staring at potentially their first loss at the Camp Nou since another Russian club, Rubin Kazan, won here in 2009.
Messi, though, put their European ambitions back on track with two poacher's goals inside the last 20 minutes.
"To start off with a win is very important and this was never going to be an easy game as we were against a Spartak side with good players including a lot of foreigners," said Barca coach Tito Vilanova.
"They closed themselves in at the back and looked to counter attack. It was that kind of game, perhaps boring.
"We pushed forward and seemed in control with a lot of chances but at the same time there is always a danger at the back.
"I can't say that I am pleased with the performance but as for the defence it is always possible that you can concede if you are so far up the pitch."
Spartak's Spanish coach Unai Emery had never beaten Barcelona during his time in charge of Almeria or Valencia and it was always likely to be a severe test.
"We are not happy obviously with the way the game turned out but if there is something good to take from it then we made it difficult for Barcelona and we know that we have a bright future," said Emery.
"I have come here before and never managed to win using different tactics.
"In the past I have tried attacking but on this occasion looking into all the variables I decided the best thing was to defend deeply and attack when we could.
"I have no regrets about the way the defence performed but I think we could have done a bit more going forward."
Tello should have given the home side the lead after 10 minutes but he scooped his shot round the post following a delightful through ball from Messi.
While Barca were dominating, their situation deteriorated at the back as Gerard Pique had to go off a couple of minutes later having injured his leg - and is expected to be out for two to three weeks - and Alex Song was forced to step into the defence.
A physical Spartak side had a distinct height advantage but it mattered little while they ball was at the other end, and Tello made up for his earlier miss with a fine shot from the edge of the area to give Barca the lead.
The youngster stepped inside Kirill Kombarov before slotting past 'keeper Andriy Dykan and into the far corner.
Vilanova's men looked comfortable at that point, but Spartak drew level from a rare breakaway, Emmanuel Emenike making a marauding run down the right before seeing his harmless pass steered into his own goal by Dani Alves on the back foot.
Barca once again went on the offensive and Spartak were left hanging on against waves of attacks, with Sergio Busquets coming within a whisker of scoring with a header which he glanced wide from a corner.
Messi forced a good save out of Dykan at one end and then Spartak stole into the lead as Aidan McGeady supplied Romulo, who finished clinically into the corner.
Vilanova took off Alves and switched to a three-man defence as they looked to get back in the game and Messi once again proved to be the difference.
He first knocked in a Tello pass from close range on 71 minutes and then headed home an Alexis Sanchez cross with ten minutes to go.