The Movistar rider finally claimed the 'rojigualda' jersey after finishing sixth in 2009, fifth in 2010 and second in the past two years.
The Basque showing beat favourite Luis Leon Sánchez by 45 seconds over the 44km course with Ruben Plaza third.
Alejandro Valverde finished in fifth place, 17 seconds off the podium.
Castroviejo said: "I was really strong all day. I had finished twice second in the last two years but I came in better physical condition to this year's race, with the only goal of winning the race.
"It was a beautiful course and a technical one - you had to distribute your energy well over it. There was a steady climb in the beginning and you couldn't give everything there. Then, there was wind halfway through the course and it made it harder - it was the crucial point to win or lose, because the final part was almost downhill, and a matter of keeping the gaps.
"After my TT in Dauphiné, I was quite confident, and I proved today my condition was good. I'm feeling well these days and I hope to do well in the Tour."
In Germany, there was no surprise as Tony Martin (Omega Pharma-Quick Step) won for the fourth time – finishing over a minute and a half ahead of Patrick Gretsch (Argos-Shimano)
In Russia, Ilnur Zakarin (RusVelo) won the title for the first time as he upset three-time champion Vladimir Gusev.
In Belarus, Kanstantsin Siutsou (Team Sky), who will back up Chris Froome at the Tour de France, took victory.
Movistar's Rui Costa won in Portugal, MTN Qhubeka's Ignatas Konovalovas claimed his fifth Lithuanian title and Team NetApp-Endura's Jan Barta defended his Czech title.
National Time Trial Results:
1 Jonathan Castroviejo (Movistar) 0:54:52
2 Luis Leon Sanchez (Blanco) 0:00:45
3 Ruben Plaza (Movistar) 0:01:46
4 Jon Izaguirre (Euskaltel-Euskadi) 0:02:03
5 Alejandro Valverde Belmonte (Movistar) 0:02:03
1 Tony Martin (Omega Pharma-Quick Step) 1:00:58
2 Patrick Gretsch (Team Argos-Shimano) 0:01:33
3 Stefan Schumacher (Christina Watches-Onfone) 0:01:53
4 Lars Teutenberg (FC Lexxi Speedbike) 0:02:48
5 Dominik Nerz (BMC Racing Team) 0:03:18
1 Ilnur Zakarin (RusVelo) 1:01:12
2 Vladimir Gusev (Katusha) 0:00:30
3 Artem Ovechkin (RusVelo) 0:00:49
4 Alexander Serov (RusVelo) 0:00:57
5 Timofey Kritsky (Katusha) 0:01:10
1 Alex Dowsett (Movistar Team) 1:02:30
2 Matthew Bottrill (www.drag2zero.com) 0:00:20
3 Ben Swift (Sky Procycling)
4 Douglas Dewey (Hennebont Cyclisme) 0:00:33
5 Luke Rowe (Sky Procycling) 0:00:49
1 Joanna Rowsell (Wiggle Honda) 0:49:26
2 Lizzy Armitstead (Dolmans Boels) 0:00:32
3 Katie Colclough (Specialized-lululemon) 0:01:37
4 Emma Trott (Dolmans Boels) 0:01:56
5 Laura Trott (Wiggle Honda) 0:02:01
1 Sylvain Chavanel (Omega Pharma - Quickstep) 0:56:48
2 Jérémy Roy (FDJ) 0:02:01
3 Johan Le Bon (FDJ) 0:02:20
4 Jérôme Coppel (Cofidis, Solutions Credits) 0:02:31
5 Sandy Casar (FDJ) 0:02:34
1 Brian Vandborg (Cannondale Pro Cycling Team) 0:48:44
2 Rasmus Christian Quaade (Team Tre-For) 0:00:06
3 Rasmus Sterobo (Team CULT Energy) 0:00:49
4 Alex Rasmussen (Team Garrmin-Sharp) 0:00:51
5 Lasse Norman Hansen (Blue Water Cycling) 0:00:55
1 Edvald Boasson Hagen (Sky Procycling) 0:36:04
2 Thor Hushovd (BMC Racing Team) 0:00:27
3 Reidar Bohlin Borgersen (Joker Merida) 0:00:42
4 Truls Engen Korsæth (Lillehammer CK) 0:01:03
5 Kjetil Johansen Amundrud (Asker CK) 0:01:18
1 Lieuwe Westra (Vacansoleil-DCM) 1:03:59.10
2 Niki Terpstra (Omega Pharma-Quickstep) 0:00:04.51
3 Tom Dumoulin (Argos-Shimano) 0:00:40.86
4 Lars Boom (Blanco Pro Cycling) 0:01:03.08
5 Stef Clement (Blanco Pro Cycling) 0:01:20.08
1 Fabian Cancellara (RadioShack Leopard) 0:50:35.391
2 Martin Elmiger (IAM Cycling) 0:00:59.228
3 Reto Hollenstein (IAM Cycling) 0:01:57.177
4 Marcel Wyss (IAM Cycling) 0:02:28.282
5 Claudio Imhof (Atlas Personal-Jakroo) 0:05:47.319
- Sports & Recreation
- Luis Leon Sánchez
- Patrick Gretsch
- Omega Pharma