The 21-year-old Barguil, winner of the 2012 Tour du Porvenir - the showcase stage race for young riders - crossed the line seven seconds ahead of Italy's Rinaldo Nocentini and Bauke Mollema of the Netherlands.
"Just getting to ride the Vuelta already was a big satisfaction for a young rider like me but this is the icing on the cake," Barguil told reporters.
"I got caught up in a big crash (on stage 10) and that was the end to my general classification hopes.
"But my sports director kept on saying 'hey, the Vuelta's not over yet' and he was right."
Barguil, whose big ambition is to win a stage on the Tour de France, said he had not been feeling in great shape during the day-long breakaway of 10 riders that culminated in his victory on the tough uphill finish at Castelldefels.
"I was lucky, no rider had any team mates in the break, so we all got tired. Then as I didn't know who was going to be fastest in a final sprint for the line, I decided to go for it from a way out," he said.
With the Vuelta heading into the Pyrenees on Saturday for the first of three stages, Nibali leads Ireland's Nicolas Roche by 31 seconds overall with Spain's Alejandro Valverde third.
"We're moving into the decisive part of the race now and it's impossible the general classification won't change in these hard mountain stages. It's not going to be easy, that's for sure," Nibali told reporters.
1. Warren Barguil (France / Argos) 4:00:13"
2. Rinaldo Nocentini (Italy / AG2R) +7"
3. Bauke Mollema (Netherlands / Belkin)
4. Ivan Santaromita (Italy / BMC Racing)
5. Xabier Zandio (Spain / Team Sky)
6. Amets Txurruka (Spain / Caja Rural)
7. Michele Scarponi (Italy / Lampre)
8. Egoi Martinez (Spain / Euskaltel)
9. Jerome Coppel (France / Cofidis) +24"
10. Benat Intxausti (Spain / Movistar) +2:34"
1. Vincenzo Nibali (Italy / Astana) 49:29:02"
2. Nicolas Roche (Ireland / Saxo - Tinkoff) +31"
3. Alejandro Valverde (Spain / Movistar) +46"
4. Chris Horner (U.S. / RadioShack)
5. Joaquim Rodriguez (Spain / Katusha) +2:33"
6. Domenico Pozzovivo (Italy / AG2R) +2:44"
7. Ivan Basso (Italy / Cannondale) +2:52"
8. Thibaut Pinot (France / FDJ.fr) +3:35"
9. Rafal Majka (Poland / Saxo - Tinkoff) +3:46"
10. Daniel Moreno (Spain / Katusha) +3:56"