After overnight leader and Astana team mate Janez Brajkovic of Slovenia lost contact with the front group on the final kilometre, Nibali now leads by eight seconds on Roche, with Spain's Haimar Zubeldia in third.
"Today was a key day and it worked out perfectly," Nibali, winner of this year's Giro d'Italia, told reporters.
"This final climb wasn't really a good one for me, it wasn't steep enough and I was basically following other guys' back wheels rather than trying to attack," the Italian, Vuelta winner in 2010, added.
"But my condition is good and I wanted to make the most of it. I had great support from my squad all the way up the climb, (Dane Jakob) Fugslang was with me and I can be very satisfied."
Asked if he had not taken the leader's jersey too early in such a gruelling three-week race which has ten mountain top finishes to come, Nibali said: "We'll just have to go on the day by day, and see what happens.
"Right now, I'm just pleased to be where I am."
Nibali's Astana squad had kept the pace high prior to the second stage's main challenge, the final 11-km ascent to the Alto do Monte da Groba, a climb rearing high above Spain's Atlantic coastline in the region of Galicia.
Three early attackers on the stage, New Zealand's Greg Henderson, Dane Alex Rasmussen and Spaniard Francisco Aramendia fell back exhausted on the climb's lower slopes as Spanish squad Movistar helped Astana pile on the pressure.
As the riders climbed through dense eucalyptus and pinewoods, the high pace saw two favourites, Spain's Samuel Sanchez and Colombian Sergio Henao, slide out of a group of 25 before Roche attacked for his first Grand Tour victory in the last kilometre.
"This is really liberating for me, I've only won eight races in my career but I've had so many second places," said Roche, whose father Stephen won the Tour de France in 1987.
"Roche is the rider who's always in the front but never able to win. I'm over the moon."
The fifth Irishman to win a stage of the Vuelta a Espana, Roche added: "I did the Tour this summer working for (Spanish team mate) Alberto (Contador), but I've always had the Vuelta as a target for the last five years and this year was no different.
"I might finish fourth, fifth or sixth overall in Madrid, but this is what counts for now."
(Editing by Rex Gowar)