Moreno attacked with conviction on the 2km climb to the finish of the 189km ride from Lalin/a Estrada to Fisterra in Galicia to hold off Fabian Cancellara (RadioShack) and Michael Matthews (Orica-GreenEdge), who finished second and third respectively.
"It was a spectacular victory, I am very happy," said Moreno, who just fell short of triumphing in Sunday's second stage, eventually won by Irishman Nicholas Roche.
"I had this stage in mind and I said to Purito (Joaquim Rodriguez) yesterday that I didn't know the climb but that I was going to try and do it.
"This year I haven't had as much luck as in the past so right now I am going to enjoy this victory."
Nibali was part of a group of 21 riders awarded the same time as Moreno that also included overall contenders Alejandro Valverde (Movistar) and Rodriguez (Katusha).
"I am surprised because I didn't got to contest the stage win," said Nibali, who is looking to win his second Tour of Spain after also claiming the Giro d'Italia this year.
"I stayed at the front of the peloton just to avoid risks and control things a bit and in the end I have left with the leader's jersey."
Veteran American Chris Horner (RadioShack), whose victory on stage three saw him wear the leader's red jersey on Tuesday, finished six seconds behind the leading pack to fall three seconds off the lead.
Saxo rider Roche, meanwhile, is a further six seconds back in the overall classification.
The stage didn't really come to life until the final stages as the peloton set a controlled pace throughout the day to prevent significant breakaways.
Nicolas Edet (Cofidis) had been part of an early five-man breakaway and attacked on his own after the short but incredibly steep climb up the Mirador de Ezaro, which included ramps with a 30% gradient.
However, the Frenchman was soon swallowed up the peloton, which then stayed together until the climb to the finish line.
Cancellara showed his hand first but Moreno produced an impressive burst in the final 500 metres to leave the Swiss trailing in his wake.
Leading results from the fourth stage of the Tour of Spain, a 189km ride from Lalin/a Estrada to Fisterra on Tuesday:
1. Daniel Moreno (ESP/RSH) 4hr37min 47sec
2. Fabian Cancellara (SWI/RSH) at s.t.
3. Micahel Matthews (AUS/OGE) s.t.
4. Gianni Meersman (BEL/OPQ) s.t.
5. Bauke Mollema (NED/BKN) s.t.
6. Edvald Boasson-Hagen (NOR/SKY) s.t.
7. Rinaldo Nocentini (ITA/ALM) s.t.
8. Warren Barguil (FRA/ARG) s.t.
9. Sergio Henao (COL/SKY) s.t.
10. Nicolas Roche (IRL/SAX) s.t.
11. Alejandro Valverde (ESP/MOV) s.t.
12. Georg Preidler (LAT/ARG) s.t.
13. Grega Bole (SLO/VCD) s.t.
14. Serge Pauwels (BEL/OPQ) s.t.
15. Joaquin Rodriguez (ESP/KAT) s.t.
16. Vincenzo Nibali (ITA/AST) s.t.
17. Anthony Roux (FRA/FDJ) s.t.
18. Ivan Santaromita (ITA/BMC) s.t.
19. Roman Kreuziger (CZE/SAX) s.t.
20. Luis Leon Sanchez (ESP/BKN) s.t.
Overall:
1. Vincenzo Nibali (ITA/AST) 14hr 15min 30sec
2. Chris Horner (USA/RSH) at 0:03s
3. Nicolas Roche (IRL/SAX) 0:08.
4. Haimar Zubeldia (ESP/RSH) 0:16.
5. Alejandro Valverde (ESP/MOV) 0:21.
6. Robert Kiserlovski (CRO/RSH) 0:26.
7. Rigoberto Uran (COL/SKY) 0:28.
8. Daniel Moreno (ESP/KAT) 0:31.
9. Roman Kreuziger (CZE/SAX) 0:42.
10. Bartosz Huzarski (POL/APP) 0:45.
11. Ivan Santaromita (ITA/BMC) 0:46.
12. Leopold Koenig (CZE/APP) 0:48.
13. Bauke Mollema (NED/BKN) 0:49.
14. Eros Capecchi (ITA/MOV) 0:52.
15. Joaquin Rodriguez (ESP/KAT) 0:53.
16. Chris Anker Sorensen (DEN/SAX) 0:55.
17. Yannick Eijssen (BEL/BMC) 0:59.
18. Laurens Ten Dam (NED/BLK) at 1:12
19. Michele Scarponi (ITA/LAM) at 1:15
20. Luis Leon Sanchez (ESP/BKN) at 1:16