The Team Sky starlet outsprinted Michal Kwiatkowski (Omega Pharma-Quickstep) and Alejandro Valverde (Movistar) after keeping with the elite group after an undulating ride.
Kwiatkowski thought he had done enough after a fine lead-out from Tony Martin, but Swift's timing was impeccable as he pulled away at the finish.
"This was one of my best days," said Swift. "It was really hard, but the legs felt very good. I liked my chances doing into that sprint."
Valverde came second as race leader Alberto Contador (Tinkoff-Saxo) retained his 12-second lead ahead of Saturday's decisive time trial.
"I had to try it, even though we knew it was going to be tough," Valverde, who lies second in the GC behind his fellow Spaniard, said. "It will be a hard time trial, especially if there is more wind against us like today."
Contador was leading entering the final kilometres but was passed by the sprinters, staying in the 16-rider leading pack to ensure he has the advantage over Valverde.
"I will treat (tomorrow's time trial) as if we had the same time," Contador said. "It is true I have a 12-second advantage, but I still think it is a very open race."
Stage 5 result
1. Ben Swift (GBR) / Team Sky: 3:57:36
2. Alejandro Valverde (ESP) / Movistar: ST
3. Michal Kwiatkowski (POL) / Omega Pharma-Quickstep
4. Tom-Jelte Slagter (NED) / Garmin-Sharp
5. Damiano Cunego (ITA) / Lampre-Merida
1. Alberto Contador (ESP) / Tinkoff-Saxo – 20.30.31hrs
2. Alejandro Valverde (ESP) / Movistar +12s
3. Damiano Cunego (ITA) / Lampre-Merida +36
4. Cadel Evans (AUS) / BMC Racing – ST
5. Jean-Christophe Peraud (FRA) / Ag2r-La Mondiale
6. Yury Trofimov (RUS) / Katusha
7. Michal Kwiatkowski (POL) / Omega Pharma-Quickstep +41
8. Mikel Landa (ESP) / Astana +54
9. Wout Poels (NED) / Omega Pharma-Quickstep +55
10. Samuel Sanchez (ESP) / BMC Racing +56
- Sports & Recreation
- Alejandro Valverde
- Michal Kwiatkowski
- Alberto Contador